【问题标题】:UIViewController device rotation delegate methods are not getting called in iOS8在 iOS8 中未调用 UIViewController 设备旋转委托方法
【发布时间】:2014-08-28 09:09:21
【问题描述】:

我一直在开发一个 iOS 7 应用程序以使其与 ios 8(测试版 5)兼容。在此应用程序中,UIViewController (vc1) 呈现另一个 UIViewController (vc2)。 vc1 支持纵向和横向方向; vc2 仅支持纵向。当出现vc2 时,它会询问vc1shouldAutorotateToInterfaceOrientation: 并返回YES

在 iOS8(Beta 5)中,willRotateToInterfaceOrientation:didRotateFromInterfaceOrientation: 没有像新的 iOS 8 API 方法 viewWillTransitionToSize 一样被调用。但是,这在 iOS7 中运行良好。

我知道 willAnimateRotationToInterfaceOrientationdidRotateFromInterfaceOrientation 在 iOS 8 中已被弃用,但即使是 iOS 8 委托方法也不会被调用。每次从vc1 启动vc2 时,屏幕总是以纵向模式加载,即使我提到支持的界面方向为横向左。

任何想法...这是 iOS8 中的错误吗?

【问题讨论】:

标签: ios ios8


【解决方案1】:

好吧,我没有最好地解决你的问题,但是一旦我有一堆在 iOS 8.1 中可以正常工作的行,我会将它们呈现给你。它们只是从 Apple API 参考中获取并进行了一些编辑。

我只是把它放在每个 VC 中,我只是在需要时编辑代码。例如,我有一个应用程序,它具有纵向的初始视图控制器,然后 VC 更改(segue 完成)为具有不同功能的 LandscapeVC。 这是导致 LandscapeView 旋转的纵向视图方法。

bool isShowingLandscapeView = false;

- (void)awakeFromNib
{
    isShowingLandscapeView = NO;
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(orientationChanged:)
                                                 name:UIDeviceOrientationDidChangeNotification
                                               object:nil];
}

- (void)orientationChanged:(NSNotification *)notification
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
        !isShowingLandscapeView)
    {
        isShowingLandscapeView = YES;
        [self performSegueWithIdentifier:@"toLandscape" sender:self];
    }

我希望我把它说得通俗易懂。不要犹豫,改进我的答案,我们都在这一生中学习!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多