需求:IOS横竖屏幕切换
2015-03-25 15:20
344 查看
需求:IOS监听横竖屏幕切换,并做相应布局调整。
实现:
1、设置监听横竖屏切换动作
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
orientation = (UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation; //This is more reliable than (self.interfaceOrientation) and [[UIDevice currentDevice] orientation] (which may give a faceup type value)
if (orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown)
{
orientation = UIDeviceOrientationPortrait;
}
2、UI布局处理
-(void)didRotate:(NSNotification *)notification{
UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
if (newOrientation != UIDeviceOrientationPortraitUpsideDown && newOrientation != UIDeviceOrientationUnknown && newOrientation != UIDeviceOrientationFaceUp && newOrientation != UIDeviceOrientationFaceDown && newOrientation != orientation){
orientation = newOrientation;
[self initWindowViews];
}
}
3、兼容性问题(网上例子,但没有测试),不加暂没发现任何问题。
// iOS5.0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationMaskAllButUpsideDown; // 可以修改为任何方向
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown; // 可以修改为任何方向
}
-(BOOL)shouldAutorotate{
return YES;
}
参考网址:
http://blog.csdn.net/openglnewbee/article/details/40404495
例子
https://github.com/Thinkerfans/ios-screenrotate-demo.git
实现:
1、设置监听横竖屏切换动作
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];
orientation = (UIDeviceOrientation)[UIApplication sharedApplication].statusBarOrientation; //This is more reliable than (self.interfaceOrientation) and [[UIDevice currentDevice] orientation] (which may give a faceup type value)
if (orientation == UIDeviceOrientationUnknown || orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown)
{
orientation = UIDeviceOrientationPortrait;
}
2、UI布局处理
-(void)didRotate:(NSNotification *)notification{
UIDeviceOrientation newOrientation = [[UIDevice currentDevice] orientation];
if (newOrientation != UIDeviceOrientationPortraitUpsideDown && newOrientation != UIDeviceOrientationUnknown && newOrientation != UIDeviceOrientationFaceUp && newOrientation != UIDeviceOrientationFaceDown && newOrientation != orientation){
orientation = newOrientation;
[self initWindowViews];
}
}
3、兼容性问题(网上例子,但没有测试),不加暂没发现任何问题。
// iOS5.0
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return UIInterfaceOrientationMaskAllButUpsideDown; // 可以修改为任何方向
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAllButUpsideDown; // 可以修改为任何方向
}
-(BOOL)shouldAutorotate{
return YES;
}
参考网址:
http://blog.csdn.net/openglnewbee/article/details/40404495
例子
https://github.com/Thinkerfans/ios-screenrotate-demo.git
相关文章推荐
- IOS 横竖屏幕切换
- IOS强制横竖屏幕切换总结续
- IOS 前后台切换
- 美Android运用拓荒职员需求逾越iOS
- ios view与view间切换的动画效果
- ios 视图切换动画效果
- iOS应用程序状态切换相关
- iOS 切换视图
- ios 视图切换动画效果
- iOS应用程序状态切换相关
- 【iOS-Cocos2d游戏开发之三】CCScene切换的所有特效(27种)以及设置屏幕横竖屏!
- ios 视图切换动画效果
- ios 视图切换动画效果
- IOS学习 -两个图片切换显示
- [IOS]iphone开发之横屏与竖屏在不同视图之间的切换
- IOS 入门开发之导航栏按钮切换(三)
- iOS程序主题切换的Demo,不用re-alloc对象
- [iOS]一种可以让UINavigationBar在自定义背景和系统背景切换的办法
- 笨鸟学iOS开发(3)view制作及切换
- IOS 入门开发之导航栏按钮切换