iOS 强制转成横屏的方式
2016-11-23 09:12
218 查看
强制转成横屏:
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];
}
以上代码支持ARC哟.
方法二: 通过判断状态栏来设置视图的transform属性。
- (void)deviceOrientationDidChange: (NSNotification *)notification
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat startRotation = [[self valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
CGAffineTransform rotation;
switch (interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 270.0 / 180.0);
break;
case UIInterfaceOrientationLandscapeRight:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 90.0 / 180.0);
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 180.0 / 180.0);
br
c7ab
eak;
default:
rotation = CGAffineTransformMakeRotation(-startRotation + 0.0);
break;
}
view.transform = rotation;
}
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];
}
以上代码支持ARC哟.
方法二: 通过判断状态栏来设置视图的transform属性。
- (void)deviceOrientationDidChange: (NSNotification *)notification
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
CGFloat startRotation = [[self valueForKeyPath:@"layer.transform.rotation.z"] floatValue];
CGAffineTransform rotation;
switch (interfaceOrientation) {
case UIInterfaceOrientationLandscapeLeft:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 270.0 / 180.0);
break;
case UIInterfaceOrientationLandscapeRight:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 90.0 / 180.0);
break;
case UIInterfaceOrientationPortraitUpsideDown:
rotation = CGAffineTransformMakeRotation(-startRotation + M_PI * 180.0 / 180.0);
br
c7ab
eak;
default:
rotation = CGAffineTransformMakeRotation(-startRotation + 0.0);
break;
}
view.transform = rotation;
}
相关文章推荐
- iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- 小胖说事30------iOS 强制转成横屏的方式
- iOS 强制转成横屏的方式
- 小胖说事30------iOS 强制转成横屏的方式
- ios 相机界面强制横屏
- iOS 强制横屏
- (转)在IOS应用中从竖屏模式强制转换为横屏模式
- iOS强制横屏
- ios强制横屏之大山(三)
- 在iOS应用中从竖屏模式强制转换为横屏模式
- iOS 强制横屏
- (转)在IOS应用中从竖屏模式强制转换为横屏模式
- ios 强制某个界面旋转成横屏
- Xcode ,Cocos2d-x,强制横屏,Bundle Identifier ,iOS 打包成.ipa,修改项目名称,同名图片替换总是显示旧图片
- ios 强制某个界面旋转成横屏
- iOS强制切换横屏、竖屏
- 在IOS应用中从竖屏模式强制转换为横屏模式
- 在IOS应用中从竖屏模式强制转换为横屏模式
- iOS 强制横屏