zoukankan      html  css  js  c++  java
  • iphone之判断屏幕方向

     有两种方法可以判断

    1,程序刚开始运行的时候,不能获取当前方向。给你说几种方式,你试一下: 1. 可以在启动后0.01秒执行初始化的代码,这个时候就可以获取设备方向了。

    2. 另外一种方式,借助状态栏的方向:

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];	
    
    

    3. 你可以通过获取控件所属controller的界面方向,使得相关控件的方向与其controller的方向是一致的,而无需理会当前的设备方向究竟是什么。控制器的界面方向可由其interfaceOrientation属性获得。 例如:

    if (self.interfaceOrientation == UIDeviceOrientationPortrait)
    

    就可以判断程序启动时是不是在protrait方向上了。

    if(self.interfaceOrientation== UIDeviceOrientationPortrait ||self.interfaceOrientation== UIDeviceOrientationPortraitUpsideDown)

    {//正

    else

    {//反

    }

     2,以下这种方法发现在模拟器上测试刚启动app后是无法得到设备方向的。 获取的结果是UIDeviceOrientationUnknown。The value of this property always returns 0 unless orientation notifications have been enabled by calling beginGeneratingDeviceOrientationNotifications. 有的说是只能在真机上才可以。

    UIDevice *device = [UIDevicecurrentDevice];

    if(device.orientation== UIInterfaceOrientationPortrait || device.orientation== UIInterfaceOrientationPortraitUpsideDown)

    {//正

    else

    {//反

    }

  • 相关阅读:
    软件工程第四次作业
    软件工程第三次作业
    图片
    软件工程第二次作业
    软件工程第一次作业
    我的大学生活-3-35-任延勇
    我的未来只有我知道
    cpu占用率高排查知识点
    LeetCode字符串题目
    hashmap
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3217044.html
Copyright © 2011-2022 走看看