在UIApplication实现该方法:
1.重写AppDelegate中的 supportedInterfaceOrientationsForWindow方法,该方法可以配置单个页面是否支持屏幕旋转。
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
UIViewController*result =nil;
result = [selfgetCurrentVC];
if ([result isKindOfClass:[xxxViewController class]]) {
return UIInterfaceOrientationMaskAll;
}else{
return UIInterfaceOrientationMaskPortrait;
}
}
2.实现获取当前屏幕正在展示的controller,用于判断当前屏幕正在展示的controller是否支持屏幕旋转
-(UIViewController *)getCurrentVC
{
UIWindow *window = [UIApplication sharedApplication].delegate.window;
if (window.windowLevel != UIWindowLevelNormal) {
NSArray*windows = [[UIApplicationsharedApplication]windows];
for(UIWindow* tmpWininwindows) {
if(tmpWin.windowLevel==UIWindowLevelNormal) {
window = tmpWin;
break;
}
}
}
UIViewController*rootVC = window.rootViewController;
UIViewController*activeVC =nil;
while(true) {
if([rootVCisKindOfClass:[UINavigationControllerclass]]) {
activeVC = [(UINavigationController*)rootVCvisibleViewController];
}elseif([rootVCisKindOfClass:[UITabBarControllerclass]]) {
activeVC = [(UITabBarController*)rootVCselectedViewController];
}elseif(rootVC.presentedViewController) {
activeVC = rootVC.presentedViewController;
}elseif(rootVC.childViewControllers.count>0) {
activeVC = [rootVC.childViewControllerslastObject];
}else{
break;
}
rootVC = activeVC;
}
returnactiveVC;
}
网友评论