ios - 在 iOS 8/9 中根据设备方向更改 Viewcontroller

标签 ios xcode swift ios8 segue

在 iOS 8/9 中基于设备方向的两个 View Controller 之间的首选方式是什么?我想构建一个以横向显示的仪器。在纵向中,我想显示应用程序的设置。

最佳答案

在 AppDelegate.swift 的“didFinishLaunchingWithOptions”函数中,我输入了:

NSNotificationCenter.defaultCenter().addObserver(self, selector: "rotated", name: UIDeviceOrientationDidChangeNotification, object: nil)

然后在 AppDelegate 类中,放置以下函数:

func rotated(){
    if(UIDeviceOrientationIsLandscape(UIDevice.currentDevice().orientation){            
        println("landscape")
    }

    if(UIDeviceOrientationIsPortrait(UIDevice.currentDevice().orientation)){
        println("Portrait")
    }
}

或者你可以使用这个:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        println("landscape")
    } else {
        println("portraight")
    }
}

关于ios - 在 iOS 8/9 中根据设备方向更改 Viewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460049/

相关文章:

ios - 如何使用 Xcode AutoLayout 调整图像大小?

ios - 属性文本居中对齐

iOS - 拒绝代码签名权限,现在无法构建

ios - 如何从 UIImagePickerController 拍摄的照片和视频中获取日期?

ios - 无法分配 UIImage 类型的值?输入 PFFile?

ios - 应用程序关闭时如何处理 UNNotificationAction?

android - 如何让两个或多个React Native应用程序彼此共享数据?

iphone - uiNavigationController 推送 View Controller 时出错

swift - 在 getDeliveredNotifications(completionHandler :) method) 中读取推送通知负载详细信息

ios - UIDatePicker 第一个值集不是默认读取