可以说,我有三个UI控制器(A,B,C)。
A是我的根控制器和ShouldAutoRotate方法里面我返回YES。 我做presentModalView从A到B(B =>此ShouldAutoRotate方法我返回肖像内),然后从BI做presentModal到C(C应能旋转到任何方向)。
现在C内我能模拟器旋转到任何方位,整个景观旋转perfectly.Here的问题是,当C是风景,我驳回,B里面所有的目标将变得一团糟! 同样的事情发生在A.
我只是需要有C上的旋转!
谢意。
可以说,我有三个UI控制器(A,B,C)。
A是我的根控制器和ShouldAutoRotate方法里面我返回YES。 我做presentModalView从A到B(B =>此ShouldAutoRotate方法我返回肖像内),然后从BI做presentModal到C(C应能旋转到任何方向)。
现在C内我能模拟器旋转到任何方位,整个景观旋转perfectly.Here的问题是,当C是风景,我驳回,B里面所有的目标将变得一团糟! 同样的事情发生在A.
我只是需要有C上的旋转!
谢意。
在应用程序的委托
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (nonatomic) BOOL shouldRotate;
@end
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
if (self.shouldRotate == YES) {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskPortrait;
}
在的viewController A,B
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
((AppDelegate *)[[UIApplication sharedApplication] delegate]).shouldRotate = NO;
[self supportedInterfaceOrientations];
[self shouldAutorotate:UIInterfaceOrientationPortrait];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
在Ç的viewController
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
((AppDelegate *)[[UIApplication sharedApplication] delegate]).shouldRotate = YES;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (BOOL)shouldAutorotate:(UIInterfaceOrientation)interfaceOrientation{
return YES;
}
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (IBAction)closeVC:(id)sender {
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.shouldRotate = NO;
[self supportedInterfaceOrientations];
[self shouldAutorotate:UIInterfaceOrientationPortrait];
[self dismissViewControllerAnimated:YES completion:nil];
}
希望这能解决你的问题
您需要允许从项目信息所有方向
,然后覆盖所有实施这些方法的目标中的每个视图控制器的iOS 6 +来启用和禁用取向。
supportedInterfaceOrientations
shouldAutorotate
shouldAutorotateToInterfaceOrientation
力旋转C到人像您关闭之前
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];