iOS两个强制旋转屏幕的方法
2015-07-22 17:43
585 查看
第一个:
[cpp] view
plaincopy
// 状态栏动画持续时间
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView animateWithDuration:duration animations:^{
// 修改状态栏的方向及view的方向进而强制旋转屏幕
[[UIApplication sharedApplication] setStatusBarOrientation:_bottomView.landscapeModel ? UIInterfaceOrientationLandscapeRight : UIInterfaceOrientationPortrait];
self.navigationController.view.transform = _bottomView.landscapeModel ? CGAffineTransformMakeRotation(M_PI_2) : CGAffineTransformIdentity;
self.navigationController.view.bounds = CGRectMake(self.navigationController.view.bounds.origin.x, self.navigationController.view.bounds.origin.y, self.view.frame.size.height, self.view.frame.size.width);
}];
第二个:
非arc:
[cpp] view
plaincopy
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
arc下:
[cpp] view
plaincopy
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeRight;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
http://blog.csdn.net/yiyaaixuexi/article/details/8035014
[cpp] view
plaincopy
// 状态栏动画持续时间
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView animateWithDuration:duration animations:^{
// 修改状态栏的方向及view的方向进而强制旋转屏幕
[[UIApplication sharedApplication] setStatusBarOrientation:_bottomView.landscapeModel ? UIInterfaceOrientationLandscapeRight : UIInterfaceOrientationPortrait];
self.navigationController.view.transform = _bottomView.landscapeModel ? CGAffineTransformMakeRotation(M_PI_2) : CGAffineTransformIdentity;
self.navigationController.view.bounds = CGRectMake(self.navigationController.view.bounds.origin.x, self.navigationController.view.bounds.origin.y, self.view.frame.size.height, self.view.frame.size.width);
}];
第二个:
非arc:
[cpp] view
plaincopy
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:)
withObject:(id)UIInterfaceOrientationLandscapeRight];
}
arc下:
[cpp] view
plaincopy
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeRight;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
http://blog.csdn.net/yiyaaixuexi/article/details/8035014
相关文章推荐
- 【iOS开发系列】用简单工厂模式理解OC反射机制
- ios MVC
- ios 自定义cell中有textField,点击textField时,防止键盘挡住textField
- 构建 iOS 风格移动 Web 应用程序的8款开发框架
- 谈谈iOS7及以上版本navigationBar带来的坑
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- 《慕客网:IOS基础入门之Foundation框架初体验》学习笔记 <三> NSArray
- ios学习笔记--(c基础题7)
- iOS DES ECB模式对称加密解密
- ios学习笔记:storyboard页面跳转
- iOS AF上传图片模拟器成功 真机不成功的问题
- IOS NSUserDefalut存储位置
- ios基础入门——malloc方法
- IOS - 修改头像
- IOS—bound和frame区别
- IOS之分析网易新闻存储数据(CoreData的使用,增删改查)
- iOS开发-Day7-C的复习
- iOS随机颜色
- ios基本概念学习
- IOS 代码生成马赛克效果