最近项目要做一个html5电子协议,里面涉及到签名,竖屏签名不够,所以需要把屏幕切换到横屏,签完字后把签字内容返回到竖屏中的方框内,由于项目不上AppStore,只用企业证书打包,所以使用下面方式来实现横竖屏切换功能。
bool isPortrait = true;
- (IBAction)changeOri:(id)sender {
if (isPortrait) {
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
[[UIDevice currentDevice] performSelector:@selector(setOrientation:) withObject:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeLeft]];
isPortrait = false;
}
}else{
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 = UIDeviceOrientationPortrait;
//从2开始是因为0 1 两个参数已经被selector和target占用
[invocation setArgument:&val atIndex:2];
[invocation invoke];
isPortrait = true;
}
}
}版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/jwzhangjie/article/details/47989443