iPhone:使用哪种方法将视图旋转回纵向方向?
我使用...
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用相同的方法,但包括一个测试来查看方向变化是什么。
但是,应使用以“will”开头的旋转方法之一来配置视图的新方向。上述方法告诉视图控制器先前方向是什么。它不会发送当前方向是什么或将是什么方向。 “will”方法允许您在新方向完成之前调整视图。
You can use the same method but include a test to see what the orientation change was.
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.
您缺少一个冒号。该方法接受一个参数,因此它是
didRotateFromInterfaceOrientation:
。didRotateFromInterfaceOrientation 是另一个有效的选择器,但它命名了一个完全不同的(可能不存在且从未被调用)方法。
据我所知,文档,同样的方法可以完成这两项工作。该方法的参数是旧方向,self.interfaceRotation 是新旋转。
因此,检查其中一个值(如果我是 iPhone 程序员,我会使用 self.interfaceRotation )来查看您现在所处的方向,并相应地更新您的视图。
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.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.