3

假设我有三个 UI 控制器(A、B、C)。

A 是我的根控制器,在 ShouldAutoRotate 方法中我返回 YES。我从A到B(B =>在我返回Portrait的ShouldAutoRotate方法中)做presentModalView,然后从BI做presentModal到C(C应该能够旋转到任何方向)。

现在在 C 内部我可以将模拟器旋转到任何方向,并且整个 View 可以完美旋转。问题是,当 C 是 Landscape 并且我将其关闭时,B 内部的所有对象都会变得混乱!!同样的事情也发生在 A 身上。

我只需要在 C 上进行轮换!!

感谢。

4

3 回答 3

1

在应用程序委托

@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;
}

在视图控制器 C

- (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];
}

希望这能解决你的问题

于 2015-02-27T18:47:15.513 回答
0

您需要允许项目信息中的所有方向

在此处输入图像描述

然后在每个视图控制器中覆盖实现所有这些方法以针对 iOS 6 + 启用和禁用方向。

supportedInterfaceOrientations

shouldAutorotate

shouldAutorotateToInterfaceOrientation
于 2015-03-03T05:48:17.970 回答
0

在您关闭它之前强制将 C 旋转到纵向

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
于 2015-03-03T06:36:55.330 回答