关于UIDeviceOrientation和UIInterfaceOrientation
1,UIDeviceOrientation 是设备的方向,只能读取不能设置,支持6个方向,
它的typedef的 NS_ENUM(NSInteger的, UIDeviceOrientation ) {
UIDeviceOrientationUnknown ,
UIDeviceOrientationPortrait , //设备垂直方向,在底部的home键
UIDeviceOrientationPortraitUpsideDown, 垂直方向,home键的顶部
UIDeviceOrientationLandscapeLeft, //设备水平方向,home键在右边
UIDeviceOrientationLandscapeRight, //设备水平方向,home键在左侧
UIDeviceOrientationFaceUp, //设备面向平板,正视
UIDeviceOrientationFaceDown //面向平板设备,脸朝下
};
UIInterfaceOrientation是软件的方向,可以读取可以设置。
它的typedef的 NS_ENUM(NSInteger的, UIInterfaceOrientation ) {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
};
注意:UIInterfaceOrientation的横屏的左边和右边跟UIDeviceOrientation刚好相反。
2、如果需要获取设备方向变化(UIDeviceOrientation)的消息的话,需要注册UIDeviceOrientationDidChangeNotification通知。
在注册通知时,需要先调用UIDevice的beginGeneratingDeviceOrientationNotifications方法
[[ UIDevice currentDevice ] beginGeneratingDeviceOrientationNotifications ]; [notificationCenter addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil];
同时,在结束时,需要移除改通知消息
[ notificationCenter removeObserver :自的 名称: UIDeviceOrientationDidChangeNotification 对象:无]; [[ UIDevice currentDevice ] endGeneratingDeviceOrientationNotifications ];
发现 b2c交易在ios6上webview随屏幕旋转了,但是b2c支持横屏的,原因是ios6的委托
iOS6下的
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}
这个不会再被调用,取而代之的是这俩个组合:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
} 当然,为了保持对旧版本系统行为的兼容性,不要删掉不用的那个调用。另外还有一个这个preferred朝向也可以加上
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}b2c交易只支持横屏,网银交易需要支持横竖屏,所以如果在info.plist设置支持的方向,则再同以客户端下两种应用有冲突。解决这个问题的方法就是再前面的基础上再应用的delegate中加入如下回调:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if (clientstate == 0) /* 网银*/
return UIInterfaceOrientationMaskAll;
else/* b2c*/
return UIInterfaceOrientationMaskLandscape;
}
简单说明:
UIInterfaceOrientationMaskLandscape 支持左右横屏
UIInterfaceOrientationMaskAll 支持四个方向旋转
UIInterfaceOrientationMaskAllButUpsideDown 支持除了UpsideDown以外的旋转
版权属于:东哥笔记 - DongGe.org
本文链接:https://blog.dongge.org/112.html
本文采用知识共享署名4.0 国际许可协议进行许可。转载或大段使用必须添加本文链接,否则您将构成侵权!
微信公众号: 东哥org

1 条评论
不错,给力!