解雇子项后,父UIViewController方向不应更改

时间:2012-08-07 12:55:21

标签: iphone xcode ios5 presentmodalviewcontroller

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

A是我的根控制器,在ShouldAutoRotate方法内,我返回YES。 我做了从A到B的礼物视图(B =>在ShouldAutoRotate方法中我返回肖像)然后从B我将presentModal转换为C(C应该能够旋转到任何方向)。

现在在C里面我能够将模拟器旋转到任何方向,整个视图旋转完美。这就是问题,当C是风景时我解雇它,B里面的所有物体都会变得混乱!同样的事情发生在A。

我只需要在C !!上进行旋转。

谢意。

3 个答案:

答案 0 :(得分:1)

在App代理

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

希望这能解决您的问题

答案 1 :(得分:0)

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

enter image description here

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

supportedInterfaceOrientations

shouldAutorotate

shouldAutorotateToInterfaceOrientation

答案 2 :(得分:0)

强制将C旋转为纵向,然后解除它

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];