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

    {//反

    }

  • 相关阅读:
    自定义dialog
    利用jquery实现自动登录
    文件的上传
    一些想法
    利用ajax实现分页效果
    自动化构建工具gulp的基础了解
    javascript模块化---requirejs
    交互ajax
    聊聊javascript的事件
    谈谈bootstrap在实践中的应用
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3217044.html
Copyright © 2011-2022 走看看