| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

IOS屏幕旋转

//在iOS5.1 和 之前的版本中, 我们通常利用 shouldAutorotateToInterfaceOrientation:   //来单独控制某个UIViewController的旋屏方向支持  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation  {      return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);  }     //但是在iOS6中,这个方法被废弃了,取而代之的是这俩个组合:  - (BOOL)shouldAutorotate  {     return YES;  }      - (NSUInteger)supportedInterfaceOrientations  {      return UIInterfaceOrientationMaskLandscape;  }     //设置View Controller被Presented时的首选显示方向。  //当view controller被presented显示时,可能在一个特定的方向显示最合适,如果其仅仅支持这一个方向  //可以在supportedInterfaceOrientations方法中简单的返回此方向,但如果view controller支持多个方向显示  //但在某一个方向显示最佳,则可以通过重写preferredInterfaceOrientationForPresentation方法来返回此方向  //这样,当view controller被presented时,将会以preferredInterfaceOrientationForPresentation返回的方向显示。  //注意:preferredInterfaceOrientationForPresentation返回的方向是supportedInterfaceOrientations中的一个。  - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation  {      return UIInterfaceOrientationLandscapeRight;  }     //如果整个应用所有view controller都不支持旋屏  - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window    {         return UIInterfaceOrientationMaskPortrait;    }     //获取到“当前interfaceOrientation  //具体区别,可参见StackOverflow的问答:  //http://stackoverflow.com/questions/7968451/different-ways-of-getting-current-interface-orientation  controller.interfaceOrientation,获取特定controller的方向  [[UIApplication sharedApplication] statusBarOrientation] 获取状态条相关的方向  [[UIDevice currentDevice] orientation] 获取当前设备的方向