Ориентацията на родителския UIViewController не трябва да се променя след отхвърляне на детето

Да кажем, че имам три UI контролера (A, B, C).

A е моят основен контролер и вътре в метода ShouldAutoRotate връщам YES. Правя presentModalView от A към B (B=>вътре в метода ShouldAutoRotate връщам Portrait), след това от B правя presentModal към C (C трябва да може да се върти във всякаква ориентация).

Сега вътре в C мога да завъртя симулатора във всякаква ориентация и целият изглед се върти перфектно. Ето го проблемът, когато C е пейзаж и аз го отхвърля, всички обекти вътре в B ще се объркат!! същото се случва и с А.

Просто трябва да имам ротация на C!!

Благодарности.


person danialmoghaddam    schedule 07.08.2012    source източник
comment
Предполагам, че въртенето трябва да зависи от всеки ViewControllers, ориентацията на един ViewController не трябва да засяга друга, защото те са напълно различен код. Сигурни ли сте, че вашите методи shouldRotate са перфектно написани   -  person TeaCupApp    schedule 07.08.2012
comment
Просто имам Return YES вътре в него.   -  person danialmoghaddam    schedule 07.08.2012


Отговори (3)


Делегат в приложението

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

Надявам се това да реши проблема ви

person Karthik Rao    schedule 27.02.2015

Трябва да разрешите всички ориентации от информацията за проекта

въведете описание на изображението тук

и след това заменете прилагането на всички тези методи за насочване към iOS 6+ във всеки контролер за изглед, за да активирате и деактивирате ориентацията.

supportedInterfaceOrientations

shouldAutorotate

shouldAutorotateToInterfaceOrientation
person khunshan    schedule 03.03.2015

принудително завъртете C до портрет, преди да го отхвърлите

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:NO];
person Hakim    schedule 03.03.2015