在iOS 8/9中根据设备方向更改Viewcontroller [英] Change Viewcontroller based on device orientation in iOS 8/9

查看:111
本文介绍了在iOS 8/9中根据设备方向更改Viewcontroller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8/9中基于设备方向在两个视图控制器之间进行区分的首选方法是什么?我想建立一个横向展示的乐器。在肖像中,我想显示应用程序的设置。

What is the preferred way of segueying between two viewcontrollers based on device orientation in iOS 8/9? I want to build an instrument that is shown in landscape. In portrait i want to show the settings of the App.

推荐答案

在didFinishLaunchingWithOptions函数中的AppDelegate.swift中我放了:

In AppDelegate.swift inside the "didFinishLaunchingWithOptions" function I put:

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

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

And then inside the AppDelegate class, put the following function:

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 8/9中根据设备方向更改Viewcontroller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆