IOS横竖屏

1.横竖屏设定

1.1XCode选择设定(整个app有效)

选择Project->Target->General->Deployment Info->Device Orientation,勾选须要支持的屏幕方向,好比 :fa-square-o:Portrait :fa-square-o:Upside Down :fa-square-o:Landscape Left :fa-square-o:Landscape Rightapp

1.2.AppDelegate.m文件中代码设定(整个app有效)

在AppDelegate.m中添加方法:ide

//IOS6及以上
  - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  NS_AVAILABLE_IOS(6_0){
    return UIInterfaceOrientationMaskPortrait;
}
1.3.单个View横竖屏设定(单个View有效)

主要依赖于如下几个函数函数

//当前viewcontroller是否支持转屏
- (BOOL)shouldAutorotate NS_AVAILABLE_IOS(6_0);

//当前viewcontroller支持哪些转屏方向
- (UIInterfaceOrientationMask)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);

//当前viewcontroller默认的屏幕方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation NS_AVAILABLE_IOS(6_0);

2.相关(ENUM)UIInterfaceOrientation说明

UIInterfaceOrientationMask ->UIInterfaceOrientation的多种组合code

UIInterfaceOrientationMaskPortrait  //竖屏
UIInterfaceOrientationMaskLandscapeLeft  //左横屏
UIInterfaceOrientationMaskLandscapeRight  //右横屏
UIInterfaceOrientationMaskPortraitUpsideDown  //竖屏(颠倒)
UIInterfaceOrientationMaskLandscape  //横屏
UIInterfaceOrientationMaskAll  //全部状态
UIInterfaceOrientationMaskAllButUpsideDown  //除颠倒竖屏外

3.转屏时触发哪些函数

<1>调用于翻转以前视频

//通常用来禁用某些控件或者中止某些正在进行的活动,好比中止视频播放。get

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(2_0,8_0);

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

<2>调用于翻转的过程当中it

//通常用来定制翻转后各个控件的位置、大小等。io

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration NS_DEPRECATED_IOS(3_0,8_0);

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator NS_AVAILABLE_IOS(8_0);

<3>调用于整个翻转完成以后。方法

//通常用来从新启用某些控件或者继续翻转以前被暂停的活动,好比继续视频播放im

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation NS_DEPRECATED_IOS(2_0,8_0);

4.判断当前屏幕状态(横/竖)

1. UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
2. UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
相关文章
相关标签/搜索