未调用iOS8接口循环方法 [英] iOS8 Interface Rotation Methods not called
问题描述
由于 willAnimateRotationToInterfaceOrientation:duration:
是已弃用,需要使用 viewWillTransitionToSize:withTransitionCoordinator:
而不是。
但是,在iOS8上的视图控制器中不会调用此方法。
还有什么我需要实现的,以便这个回调工作吗?
However, this method does not get called in my view controller on iOS8. Is there anything else, I need to implement, in order for this callback to work?
我在文档中找不到任何内容。我唯一能找到的是,它属于新的 UIContentContainer
协议。但是,即使我明确地将它添加到我的控制器的协议中,它也不起作用。
I cannot find anything in the documentation. The only thing I could find, was that it belongs to the new UIContentContainer
protocol. However, even if I am adding this to the protocols of my controller explicitly, it does not work.
任何想法?
推荐答案
viewWillTransitionToSize:withTransitionCoordinator:
似乎只有在接口实际要改变大小时才有效,这意味着我们已经轮换90度。如果您的布局上有一个仅允许横向的蒙版,当旋转180度时,界面大小不会改变,因此似乎不会调用此方法。
The viewWillTransitionToSize:withTransitionCoordinator:
seems to only work if the interface is actually going to change size, meaning we have rotated 90 degrees. If you have a mask on your layout that only allows landscape, when rotation 180 degrees, the interface size doesn't change, so this method doesn't seem to be called.
我已经在我的应用程序中解决了这个问题,而是注册到 UIDeviceOrientationDidChangeNotification
通知,例如:
I have worked around this in my app by instead registering to the UIDeviceOrientationDidChangeNotification
notification like:
(在我的查看控制器的 viewWillAppear
):
(In my view controller's viewWillAppear
):
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
(一个在我的 viewWillDisappear
[记得要取消订阅])
(An in my viewWillDisappear
[remember to unsubscribe])
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
我的 deviceOrientationDidChange:
看起来像:
- (void)deviceOrientationDidChange:(NSNotification *)notification {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:orientation duration:1.0];
}
这篇关于未调用iOS8接口循环方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!