关于通过屏幕旋转确定view的layout的问题
2017-03-22 12:52
316 查看
之前在项目中,有一个UIImageView需要通过接收屏幕旋转的通知来计算它的大小及位置,开始我选择接收
UIDeviceOrientationDidChange通知来处理,后来发现个别情况计算出来的大小位置不对,经过排查发现我的代码里只处理是水平还是垂直的逻辑,然而device的orientation却还包含了face up和face down的情况,并且即便你的app并不支持这俩个orientation,但是由于orientation确实改变了,所以还是会接到。但我确实不需要这俩个orientation,经过查找资料,得到如下答复“
Apple recommends against using device orientation for view layout. Instead, each view controller has an interfaceOrientation property,
and
a statusBarOrientation property,
both of which will return the current interface orientation, which is suitable for view layout.
To monitor for changes, there are
like willRotateToInterfaceOrientation:duration: that
will be called and notifications such as UIApplicationWillChangeStatusBarOrientationNotification that
will be posted when an interface orientation change occurs.
”,大致意思是说,苹果并不支持你去使用device的orientation改变这个通知,去确定你的view的layout,而每个viewcontroller有其自己的interface orientation属性,同时整个app的uiapplication有一个statusbar orientation的属性,在答复的最下面,也给出了,你可以通过接收 UIApplicationWillChangeStatusBarOrientationNotification来获取屏幕旋转的通知,而这个通知最棒的地方也就在于,它只处理垂直和水平俩种情况,很显然,因为statusbar位置的改变也就只关心垂直还是水平!
至此,这个关于屏幕旋转的通知基本上就清楚了,如果你只关心水平和垂直之间的改变,那么请选择接收 UIApplicationWillChangeStatusBarOrientationNotification,因为接收UIDeviceOrientationDidChange所带来的face
up和face down可能会给你的逻辑处理带来意想不到的BUG,如果你需要face up和face down的改变,比如有些需求需要face down的时候屏幕变暗等,那么你需要接收它来详细的区分各种orientation~
总之,慎重使用UIDeviceOrientationDidChange来确定view的layout(其实最好不要用,官方不推荐,本身也有更好的)~
UIDeviceOrientationDidChange通知来处理,后来发现个别情况计算出来的大小位置不对,经过排查发现我的代码里只处理是水平还是垂直的逻辑,然而device的orientation却还包含了face up和face down的情况,并且即便你的app并不支持这俩个orientation,但是由于orientation确实改变了,所以还是会接到。但我确实不需要这俩个orientation,经过查找资料,得到如下答复“
Apple recommends against using device orientation for view layout. Instead, each view controller has an interfaceOrientation property,
and
UIApplicationhas
a statusBarOrientation property,
both of which will return the current interface orientation, which is suitable for view layout.
To monitor for changes, there are
UIViewControllermethods
like willRotateToInterfaceOrientation:duration: that
will be called and notifications such as UIApplicationWillChangeStatusBarOrientationNotification that
will be posted when an interface orientation change occurs.
”,大致意思是说,苹果并不支持你去使用device的orientation改变这个通知,去确定你的view的layout,而每个viewcontroller有其自己的interface orientation属性,同时整个app的uiapplication有一个statusbar orientation的属性,在答复的最下面,也给出了,你可以通过接收 UIApplicationWillChangeStatusBarOrientationNotification来获取屏幕旋转的通知,而这个通知最棒的地方也就在于,它只处理垂直和水平俩种情况,很显然,因为statusbar位置的改变也就只关心垂直还是水平!
至此,这个关于屏幕旋转的通知基本上就清楚了,如果你只关心水平和垂直之间的改变,那么请选择接收 UIApplicationWillChangeStatusBarOrientationNotification,因为接收UIDeviceOrientationDidChange所带来的face
up和face down可能会给你的逻辑处理带来意想不到的BUG,如果你需要face up和face down的改变,比如有些需求需要face down的时候屏幕变暗等,那么你需要接收它来详细的区分各种orientation~
总之,慎重使用UIDeviceOrientationDidChange来确定view的layout(其实最好不要用,官方不推荐,本身也有更好的)~
相关文章推荐
- ios 关于 通过加载 xib 生成的view,调用 addsubviews,sub view的按钮 不相应点击事件的 问题
- 关于IOS屏幕的旋转问题
- iOS开发:关于屏幕旋转问题
- ANDROID中使用VIEWFLIPPER类实现屏幕切换(关于坐标轴的问题已补充更改)
- 关于在新建的package中用SetContentView()函数时无法找到已创建的R.layout的布局文件的的问题的解决办法
- 关于屏幕旋转的问题
- 自定义组合控件关于LayoutInflater.from(context).inflate(R.layout.view_title, this,true)的问题
- 关于WebView加载html图文时图像适配屏幕的问题
- 关于通过UINavigationController push 过去到一个view controller而这个viewvontroller的viewwillappear不执行的问题
- Android中使用ViewFlipper实现屏幕页面切换(关于坐标轴的问题已补充更改)
- 【android】关于使用ViewPager和LayoutInflater的出现问题
- iOS 开发,屏幕旋转、旋转屏幕collectionView cell 的自动布局问题
- ZBarReaderView屏幕旋转问题
- 关于iOS TableView旋转后头部空白的问题
- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- 关于设备屏幕自动旋转一些问题
- ZBarReaderView屏幕旋转问题
- ios 关于禁止屏幕旋转问题的解决
- 关于屏幕的旋转问题
- 通过View.post()获取View的宽高引发的两个问题:1post的Runnable何时被执行,2为何View需要layout两次;以及发现Android的一个小bug