切换到横向视图并使用选项卡栏控制器

发布于 2024-12-15 05:35:24 字数 906 浏览 2 评论 0原文

我正在为我的应用程序使用标签栏控制器。如果我在一个名为“结果”的视图控制器中,并且 ios 设备旋转到横向模式,它会切换到我创建的另一个名为 landScape 的视图。这是在方法中完成的

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view=landScape;
    } else {
        self.view=originalView;
    }
}

,只要我位于选项卡栏内的特定控制器(示例结果视图控制器)中,它就可以正常工作。然而;如果我转到选项卡栏控制器中的另一个元素,并且我的手机在横向模式下倾斜,然后我决定转到 resultsviewcontroller,它不会调用我的视图 landScape,而是尝试自行自动调整视图大小,并且看起来可怕。我应该在 viewDidLoad 方法中调用方法 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientationuration:(NSTimeInterval)duration 来解决问题吗?或者这是完全错误的?

先感谢您!

I am using a tab bar controller for my app. If I'm in one of the view controllers called "results" and the ios device rotates to landscape mode, it switches for another view I created called landScape. This has been done within the method

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view=landScape;
    } else {
        self.view=originalView;
    }
}

It works just fine whenever I am in that specific controller within the tab bar (example results view controller). However; If I go to another element in my tab bar controller and my phone is tilted in landscape mode and then I decide to go to resultsviewcontroller, it does not call upon my view landScape, instead it tries to autosize the view on its own and it looks awful. Should I call the method -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration within my viewDidLoad method to solve the problem? Or is this completely wrong?

Thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-12-22 05:35:24

问题是您仅在 resultsViewController.view 是活动视图控制器并检测到旋转时才设置它。试试这个:

- (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    self.view = UIInterfaceOrientationIsPortrait(orientation)
        ? originalView
        : landScape;
}

- (void)viewWillAppear
{
    [self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
    [super viewWillAppear];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [self setViewForInterfaceOrientation:toInterfaceOrientation];
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

The problem is you're only setting resultsViewController.view when it is the active view controller and detects a rotation. Try this:

- (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    self.view = UIInterfaceOrientationIsPortrait(orientation)
        ? originalView
        : landScape;
}

- (void)viewWillAppear
{
    [self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
    [super viewWillAppear];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [self setViewForInterfaceOrientation:toInterfaceOrientation];
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文