显示视图时处理方向
当方向改变时,我对 UIView 进行了一些更改。这很好用。在手机方向已切换后添加视图时会出现问题。这会导致不会调用任何旋转方法,因此不会给我进行更改的机会。
处理这个问题的正确方法是什么,可能是在 ViewDidLoad 中?我能够检测到此时的当前方向吗?
请记住,我需要进行一些小的更改,所以我不想加载不同的笔尖或类似的东西
非常感谢:)
编辑*只是为了澄清事情:正如我提到的,视图是当设备方向改变时,甚至还没有实例化。方向变为横向 ->用户单击显示另一个视图的按钮 ->创建并显示这个新视图,但其默认位置是纵向 ->当显示视图时,我在 willAnimateRotationToInterfaceOrientation 方法中重新排列的元素位于错误的位置。
I have a few changes that get made to a UIView when the orientation changes. This works fine. The problem arises when adding the view after the phones orientation is already switched. This causes none of the rotate methods to be called and therefor does not give me the opportunity to make changes.
What would be the correct way of handling this, probably in ViewDidLoad? Would I be able to detect the current orientation at that point?
Bare in mind that its a few minor changes that I would need to make, so I dont want to load a different nib or anything like that
Thanks you very much :)
EDIT* just to clear things up: As I mentioned, the view is not even instantiated yet when the device orientation changes. The orientation changes to landscape -> the user clicks a button that shows another view -> this new view gets created and shown, but its default positioning is for portrait orientation -> when the view is shown, the elements I rearrange in the willAnimateRotationToInterfaceOrientation method are in the wrong position.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,我将用户旋转设备(主要是操作视图帧)时发生的动画放在 willAnimateToInterfaceOrientation 方法中。在它的骨架形式中,它看起来像这样:
编辑:在我需要记住设备旋转以供将来使用的情况下,我在我的视图控制器类中设置了一个名为 currentOrientation (类型 int)的 ivar,然后执行以下操作
:在视图控制器中运行方法,我知道设备处于哪个方向。
Typically I put the animations that occur when the user rotates the device (manipulating the frames of views mostly) in the willAnimateToInterfaceOrientation method. In it's skeleton form it would look like this:
EDIT: In situations where I need to remember the device rotation for future use, I set up an ivar in my view controller class called currentOrientation (type int), and then do this:
Then while running the methods in the view controller, I know which orientation the device is in.