移动办公平台查看附件时支持横竖屏。而我们的app为了布局问题,没有支持横屏。我们就用下面的方法来使一个页面支持横竖屏。
在支持横竖屏的页面viewWillDisappear中使用一下代码:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = 1;
}
- (void)viewWillDisappear:(BOOL)animated
{
AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
delegate.allowRotate = 0;
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];
}
}
接着在appDelegate.h文件中声明
@property (nonatomic,assign)NSInteger allowRotate;
在appDelegate.m文件中添加一下方法:
//此方法会在设备横竖屏变化的时候系统会调用
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
// NSLog(@"方向 ============= %ld", _allowRotate);
if (_allowRotate == 1) {
return UIInterfaceOrientationMaskAll;
}else{
return (UIInterfaceOrientationMaskPortrait);
}
}
// 返回是否支持设备自动旋转
- (BOOL)shouldAutorotate
{
if (_allowRotate == 1) {
return YES;
}
return NO;
}
使其开放系统的横竖屏
知行办公,专业移动办公平台https://zx.naton.cn/
【总监】十二春秋之,3483099@qq.com;
【Master】zelo,616701261@qq.com;
【运营】狼行天下,897221533@qq.com;****
【产品设计】流浪猫,364994559@qq.com;
【体验设计】兜兜,2435632247@qq.com;
【iOS】淘码小工,492395860@qq.com;iMcG33K,imcg33k@gmail.com;
【Android】人猿居士,1059604515@qq.com;思路的顿悟,1217022114@qq.com;
【java】首席工程师MR_W,feixue300@qq.com;
【测试】土镜问道,847071279@qq.com;
【数据】喜乐多,42151960@qq.com;
【安全】保密,你懂的。
网友评论