IOS6 rotation problem

I know that you need to use the new rotation methods for iOS6, but it seems that the method I wrote does not work.

I set my plist file to allow all rotations, but not portraitUpsideDown

Then I had the following in appDelegate :

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window setRootViewController:navController];  //add nav controller to be the root view

Then in my root element, to click on another controller, I have:

WebViewViewController *webController = [[JBWebViewViewController alloc] init];
webController.urlString =   urlName;
[self.navigationController pushViewController:webController animated:YES];

And in the web controller, I have:

#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
//only allow landscape
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

/for 6.0+
- (BOOL)shouldAutorotate{
return NO;
}

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

What I want to do is allow 3 rotations in the root view, but when switching to the web view (note that I click navigation and not add subview), I only want to allow portrait view.

Someone helps me

------- UPDATE ----------

NavController UINavigationController, BOOL landscapeModeOn, ,

#pragma mark - System Rotation Methods
//for any version before 6.0
- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
  if (landscapeModeOn) {
    return interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
  } else {
    return interfaceOrientation == UIInterfaceOrientationPortrait;
  }
}

//for 6.0+
- (NSUInteger)supportedInterfaceOrientations{
  if (landscapeModeOn) {
    return UIInterfaceOrientationMaskAllButUpsideDown;
  } else {
    return UIInterfaceOrientationMaskPortrait;
  }
}

- (BOOL)shouldAutorotate{
  UIInterfaceOrientation ori = [UIDevice currentDevice].orientation;
  if (landscapeModeOn) {
    return ori != UIInterfaceOrientationPortraitUpsideDown;
  } else {
    return  ori == UIInterfaceOrientationPortrait;
  }
}

subviews :

- (void)viewWillAppear:(BOOL)animated{
  //get nav controller and turn off landscape mode
  JBNavController *navController = (JBNavController*)self.navigationController;
  [navController setLandscapeModeOn:NO];
  [navController shouldAutorotate];
}

-------------------- . IOS6 Apple Storyboard AutoLayout , IOS6 ios 4.3 ios 5

applefreak, :

.

, , , , , .

+5
3

!

- (BOOL)shouldAutorotate{
    return NO;
}

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

, supportInterfaceOrientations , shouldAutoRotate YES. , .

self.viewController self.viewController root view controller not navigationController, ! . HAS-A . / ShouldAutoRotate, ​​ . , .

, BaseviewController YES mustAutoRotate UIInterfaceOrientationPortrait , webviewController . , .

+2

shouldAutorotate supportedInterfaceOrientations. iOS6 iOS5, , , . , .

, :

- (BOOL)shouldAutorotate
{
    return self.topViewController.shouldAutorotate;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return self.topViewController.supportedInterfaceOrientations;
}

view , .

, .

+6

iOS5 iOS6

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(interfaceOrientation))  
    { 
        // here to  implement landscope code
    }

    else
    {  
        // here to  implement setframePortrait
    }
}
0

All Articles