iOS 屏幕旋转常用方式
来源:互联网 发布:网络许可 英文 编辑:程序博客网 时间:2024/06/01 08:48
//此方法在进入应用和当屏幕旋转的额时候,会调用
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
if (self.direction == SuportDirectionRight) {
return UIInterfaceOrientationMaskLandscapeRight;
} else if (self.direction == SuportDirectionPortrait){
return UIInterfaceOrientationMaskPortrait;
} else {
return UIInterfaceOrientationMaskAll;
}
}
//这一步,是必须的,因为在进入目标的VC之后,需要回调上述的APPdelegate方法
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
app.direction = SuportDirectionRight;
UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ViewController *VC = [board instantiateViewControllerWithIdentifier:@"ViewController"];
//必须将目标的VC设置为navigationVC,如果前一个VC为navigationVC就不用这一步
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:VC];
nav.navigationBarHidden = YES;
[self presentViewController:nav animated:NO completion:^{
noCurrentVC = NO;
}];
- (BOOL)prefersStatusBarHidden {
return YES;
}
-(BOOL)shouldAutorotate {
return YES;
}
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationLandscapeRight;
}
强制屏幕旋转
#pragma - mark 进入全屏
-(void)begainFullScreen {AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.shouldChangeOrientation = YES;
[[UIDevice currentDevice] setValue:@"UIInterfaceOrientationLandscapeLeft" forKey:@"orientation"];
int count = [UIApplication sharedApplication].windows.count;
NSLog(@"%@", [UIApplication sharedApplication].windows.lastObject.subviews.firstObject);
NSLog(@"key=%@",[UIApplication sharedApplication].windows);
//强制zhuan'p:
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)] && count==4) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeLeft;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
#pragma - mark 退出全屏
-(void)endFullScreen {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.shouldChangeOrientation = NO;
//强制归正:
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 =UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
- iOS 屏幕旋转常用方式
- ios屏幕旋转的两种实现方式
- iOS开发中禁止屏幕旋转的2种方式
- iOS手动旋转屏幕、自动旋转屏幕
- ios屏幕旋转注意事项
- iOS强制旋转屏幕
- ios 锁定 屏幕旋转
- ios旋转屏幕总结
- [IOS] 屏幕旋转控制
- iOS屏幕旋转
- 手动旋转iOS屏幕
- iOS屏幕旋转
- ios屏幕旋转
- iOS屏幕旋转
- IOS屏幕旋转
- iOS 屏幕旋转
- ios屏幕强制旋转
- ios 屏幕旋转
- parent&&openrt的区别
- 前端通信(ajax JSOP SSE websocket)
- Liunx基础命令
- 医院排班算法 护士排班法
- jquery ocupload一键上传文件应用
- iOS 屏幕旋转常用方式
- GitHub在linux中的配置SSH
- 原生ajax发送post请求
- python的setattr,getattr,hasattr
- WIN32和_WIN32的区别
- win7下简单FTP服务器搭建
- ADB常用命令
- Kotlin 第十三章:嵌套类、枚举类
- java作业