iPhone:使用哪种方法将视图旋转回纵向方向?

发布于 2024-08-28 15:41:53 字数 143 浏览 7 评论 0原文

我使用...

-(void)didRotateFromInterfaceOrientation:

...来调整已旋转为横向的视图。

但是,当视图需要旋转回纵向时,我不知道该使用哪种方法。

I use...

-(void)didRotateFromInterfaceOrientation:

... to adapt a view that has been rotated to landscape.

However, I don't know which method to use when the view needs to be rotated back to portrait.

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

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

发布评论

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

评论(2

恋你朝朝暮暮 2024-09-04 15:41:53

您可以使用相同的方法,但包括一个测试来查看方向变化是什么。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    switch fromInterfaceOrientation {
        case UIInterfaceOrientationPortrait {
            //... handle roation from portrait
            break;
        }
        case  UIInterfaceOrientationLandscapeLeft {
            //... handle roation LandscapeLeft
            break;
        }
        //.. and so on
    }
}

但是,应使用以“will”开头的旋转方法之一来配置视图的新方向。上述方法告诉视图控制器先前方向是什么。它不会发送当前方向是什么或将是什么方向。 “will”方法允许您在新方向完成之前调整视图。

You can use the same method but include a test to see what the orientation change was.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    switch fromInterfaceOrientation {
        case UIInterfaceOrientationPortrait {
            //... handle roation from portrait
            break;
        }
        case  UIInterfaceOrientationLandscapeLeft {
            //... handle roation LandscapeLeft
            break;
        }
        //.. and so on
    }
}

However, configuring a view for its new orientation should be done in one of the rotation methods that begin with "will". The above method tells the view controller what the previous orientation was. It doesn't send what the current orientation is or will be. The "will" methods allow you adapt the view before the new orientation completes.

孤独难免 2024-09-04 15:41:53

我使用 (void)didRotateFromInterfaceOrientation 在启用旋转时调整视图......

您缺少一个冒号。该方法接受一个参数,因此它是 didRotateFromInterfaceOrientation:

didRotateFromInterfaceOrientation 是另一个有效的选择器,但它命名了一个完全不同的(可能不存在且从未被调用)方法。

...但是,有什么方法或如何检测 iPhone 回到垂直位置以便重新适应视图???

据我所知,文档,同样的方法可以完成这两项工作。该方法的参数是旧方向,self.interfaceRotation 是新旋转。

因此,检查其中一个值(如果我是 iPhone 程序员,我会使用 self.interfaceRotation )来查看您现在所处的方向,并相应地更新您的视图。

I use (void)didRotateFromInterfaceOrientation to adapt view when rotation is enabled …

You're missing a colon. The method takes an argument, so it's didRotateFromInterfaceOrientation:.

didRotateFromInterfaceOrientation is another valid selector, but it names a completely different (and probably non-existent and never-called) method.

… but, wich method or how to detect that iphone got back to vertical position in order to readapt view???

As near as I can make out from the documentation, the same method does both jobs. The argument to the method is the old orientation, and self.interfaceRotation is the new rotation.

So, check one of those values (I'd use self.interfaceRotation if I were an iPhone programmer) to see which orientation you're in now, and update your view accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文