我正在使用UISplitViewController
创建应用,但它需要在Ipad中仅显示纵向模式下的MasterViewController
(与iPhone上的纵向模式相同)。在横向模式下,它可以正常工作。
请给我一些想法。提前谢谢。
答案 0 :(得分:0)
plz在app delegate class
中使用此代码 -(id)getTopViewController{
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
if (![topController isKindOfClass:[NSNull class]]) {
return topController;
}
}
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
UIViewController *viewOb = [self getTopViewController];
if ([viewOb isKindOfClass:[MasterViewController class]]) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAll;
}
答案 1 :(得分:0)
将其放入viewWillAppear
NSNumber *value = [NSNumber numberWithInt: UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
答案 2 :(得分:0)
请使用此代码,它将帮助您
- (BOOL)shouldAutorotate{
//disable rotation
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
//allow only portrait interface orientation
return UIInterfaceOrientationMaskPortrait;
}