美文网首页
iOS横屏设置方式

iOS横屏设置方式

作者: Star_Liu | 来源:发表于2017-03-02 09:15 被阅读0次

- 1.界面旋转,MainScreen的宽高不变,键盘位置不变

'''

CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:duration];

self.view.transform =CGAffineTransformMakeRotation(M_PI/2);

[UIView commitAnimations];

'''

2.界面旋转,MainScreen的宽高改变,键盘位置不变

复制代码

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];

}

复制代码

3.界面旋转,MainScreen的宽高改变,键盘位置改变

a.General—>中勾选Lnadscape Left/Lnadscape Right

Pasted Graphic.tiff

b.控制器中实现以下两个方法:

复制代码

// 支持设备自动旋转

- (BOOL)shouldAutorotate

{

return YES;

}

/**

*  设置特殊的界面支持的方向,这里特殊界面只支持Home在右侧的情况

*/

- (UIInterfaceOrientationMask)supportedInterfaceOrientations

{

return UIInterfaceOrientationMaskLandscapeRight;

}

复制代码

PS:如何判断当前是否横屏,一下3个方法都可以

self.interfaceOrientation(iOS 2.0~8.0)

[UIApplication sharedApplication] statusBarOrientation]

[[UIDevice currentDevice] orientation]

相关文章

网友评论

      本文标题:iOS横屏设置方式

      本文链接:https://www.haomeiwen.com/subject/qczsjttx.html