iOS强制切换横屏、竖屏
2013-03-04 18:26
323 查看
切换横竖屏最直接的方式是调用device的setOrientation方法。但是从sdk3.0以后,这个方法转为似有API,如果要上AppStore的话,要慎用!
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
第二种方式是手动的设置界面元素的旋转,包括状态栏、导航栏和视图。以下代码为从竖屏设置为横屏,坐标系是以竖屏的为基准,所以会出现负数的坐标值。
//设置状态栏旋转
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRight animated:YES];
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
//设置旋转动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
//设置导航栏旋转
self.navigationController.navigationBar.frame = CGRectMake(-204, 224, 480, 32);
self.navigationController.navigationBar.transform = CGAffineTransformMakeRotation(M_PI*1.5);
//设置视图旋转
self.view.bounds = CGRectMake(0,
-54, self.view.frame.size.width, self.view.frame.size.height);
self.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);
[UIView commitAnimations];
来源: <http://blog.csdn.net/dickenslian/article/details/7407221>
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
{
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
第二种方式是手动的设置界面元素的旋转,包括状态栏、导航栏和视图。以下代码为从竖屏设置为横屏,坐标系是以竖屏的为基准,所以会出现负数的坐标值。
//设置状态栏旋转
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRight animated:YES];
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
//设置旋转动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
//设置导航栏旋转
self.navigationController.navigationBar.frame = CGRectMake(-204, 224, 480, 32);
self.navigationController.navigationBar.transform = CGAffineTransformMakeRotation(M_PI*1.5);
//设置视图旋转
self.view.bounds = CGRectMake(0,
-54, self.view.frame.size.width, self.view.frame.size.height);
self.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);
[UIView commitAnimations];
来源: <http://blog.csdn.net/dickenslian/article/details/7407221>
相关文章推荐
- iOS强制切换横屏、竖屏
- IOS 应用中从竖屏模式强制转换为横屏模式
- iOS:手机横屏时,按下横屏视图上的导航条“返回”按钮后,切换为另一个竖屏视图
- 在iOS应用中从竖屏模式强制转换为横屏模式
- iOS强制横屏或强制竖屏
- [IOS]iphone开发之横屏与竖屏在不同视图之间的切换
- iOS 个别页面强制横屏,其他页面竖屏
- Android强制设置横屏或竖屏 切换的问题
- iOS强制切换横屏、竖屏
- iOS横屏、竖屏切换
- 在IOS应用中从竖屏模式强制转换为横屏模式
- IOS开发——强制横屏/强制竖屏
- 在IOS应用中从竖屏模式强制转换为横屏模式
- iOS中将个别页面强制横屏其他页面竖屏
- Android强制切换横屏竖屏不起作用的解决办法
- (转)在IOS应用中从竖屏模式强制转换为横屏模式
- iOS 个别页面强制横屏,其他页面竖屏
- [IOS]iphone开发之横屏与竖屏在不同视图之间的切换
- 在IOS应用中从竖屏模式强制转换为横屏模式
- 在iOS应用中从竖屏模式强制转换为横屏模式