温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ios屏幕旋转

发布时间:2020-07-31 22:52:29 来源:网络 阅读:352 作者:guoleiappleapp 栏目:移动开发

手机屏幕旋转时,试图控制器可以相应一些方法,可以再这些方法里自己布局视图


旋转方向的枚举类型

typedefNS_ENUM(NSInteger, UIInterfaceOrientation) {

   UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,

   UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

   UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,

   UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft

};



是否支持旋转

- (BOOL)shouldAutorotate

{

NSLog(@"%s",__FUNCTION__);

returnNO;

}


在旋转某一个方向时,是否支持旋转

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation

{

NSLog(@"%s",__FUNCTION__);

returnNO;

}




将要旋转时走的方法,可以判断要转向的方向

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

NSLog(@"%s  %f",__FUNCTION__,duration);

}


视图将要布局子视图

window调整显示的view controller的bounds,由于view controller的bounds发生变化,将会触发 viewWillLayoutSubviews 方法。

- (void)viewWillLayoutSubviews

{

NSLog(@"%s",__FUNCTION__);

}


视图完成布局子视图

- (void)viewDidLayoutSubviews

{

NSLog(@"%s",__FUNCTION__);

}


接着当前view controller的 willAnimateRotationToInterfaceOrientation:duration: 方法将会被调用。系统将会把该方法中执行的所有属性变化放到动animation block中。

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

NSLog(@"%s  %f",__FUNCTION__,duration);

}


旋转完成执行的方法

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

{

NSLog(@"%s",__FUNCTION__);

}














向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI