方向不适用于ios6?

我在ios6的定位问题。 相同的代码工作正常的ios5或5.1。 我用- (BOOL) shouldAutorotate and -(NSInteger)supportedInterfaceOrientations按照ios6标准。 但是仍然会“ willRotateToInterfaceOrientation ”和“ didRotateToInterfaceOrientation ”不被调用。

这是我的代码:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { CGRect frame; int viewAlpha; lastOrientation = toInterfaceOrientation; if (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone]; viewAlpha = 1; [MovieControlContainerLandscape setHidden:YES]; if (isDauntless) { [self.navigationController setNavigationBarHidden:NO animated:YES]; } else { [self.navigationController setNavigationBarHidden:NO]; } frame = iPad ? CGRectMake(0, 88, 768, 432) : CGRectMake(0, 88, 320, 180); [movieContainer removeGestureRecognizer:toggleMediaControl]; } else { [PromptToBuy dismissWithClickedButtonIndex:0 animated:YES]; [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; viewAlpha = 0; [MovieControlContainerLandscape.layer setCornerRadius:22]; [MovieControlContainerLandscape.subviews.lastObject addSubview:[MediaControls use]]; if (isDauntless) { [self.navigationController setNavigationBarHidden:YES animated:YES]; } else { [self.navigationController setNavigationBarHidden:YES]; } frame = iPad ? CGRectMake(0, 0, 1024, 768) : CGRectMake(0, 0, 480, 320); [movieContainer addGestureRecognizer:toggleMediaControl]; if (isDauntless) { [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.6]; } if(TSFullScreen) { [movieContainer setAlpha:1]; } if (isDauntless) { [UIView commitAnimations]; } } [viewContainer setAlpha:viewAlpha]; // Size the overlay view for the current orientation. [movieContainer setFrame:frame]; } } /* Sent to the view controller after the user interface rotates. */ - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { if (!UIInterfaceOrientationIsPortrait(lastOrientation) || !UIInterfaceOrientationIsPortrait(fromInterfaceOrientation)) if (!UIInterfaceOrientationIsLandscape(lastOrientation) || !UIInterfaceOrientationIsLandscape(fromInterfaceOrientation)) { float duration = .5; if (fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { if (isDauntless) { [UIView transitionWithView:movieContainer duration:duration options:UIViewAnimationOptionTransitionNone animations:^{ /* Move movie view to parent center. */ [self.moviePlayerController.view setCenter:movieContainer.center]; } completion:^(BOOL finished) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:duration]; CGRect frame = movieContainer.frame; /* Size movie view to fit parent view. */ frame.origin.y = 0; [self.moviePlayerController.view setFrame:frame]; [UIView commitAnimations]; CGPoint center = CGPointMake(movieContainer.center.x, -50); [MovieControlContainerLandscape setTag:0]; [MovieControlContainerLandscape setHidden:NO]; [MovieControlContainerLandscape setCenter:center]; [self toggleMovieController]; }]; } else { CGRect frame = movieContainer.frame; /* Size movie view to fit parent view. */ frame.origin.y = 0; [self.moviePlayerController.view setFrame:frame]; CGPoint center = CGPointMake(movieContainer.center.x, -50); [MovieControlContainerLandscape setTag:0]; [MovieControlContainerLandscape setHidden:NO]; [MovieControlContainerLandscape setCenter:center]; [self toggleMovieController]; } } else { if (!isDauntless) { [MovieControlContainer setFrame:CGRectMake(0, 44, 768, 68)]; } [MovieControlContainer addSubview:[MediaControls use]]; //NSLog(@"MovieControlContainer is %@, MovieControlContainer subviews: %@",MovieControlContainer,[MovieControlContainer subviews]); if (isDauntless) { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:duration]; } if(TSFullScreen){ [movieContainer setAlpha:0]; } CGRect frame = movieContainer.frame; /* Size movie view to fit parent view. */ frame.origin.y = 0; [self.moviePlayerController.view setFrame:frame]; if (isDauntless) { [UIView commitAnimations]; } } } } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return !mediaTypeIsAudio && isOrientationSupported; } //----supported method for ios6--------// - (BOOL) shouldAutorotate { return YES; } -(NSInteger)supportedInterfaceOrientations{ NSInteger mask = 0; if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight]) mask |= UIInterfaceOrientationMaskLandscapeRight; if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft]) mask |= UIInterfaceOrientationMaskLandscapeLeft; if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait]) mask |= UIInterfaceOrientationMaskPortrait; if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown]) mask |= UIInterfaceOrientationMaskPortraitUpsideDown; return mask; } //i have set the rootviewcontroller in appdelegate file self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController]; self.window.rootViewController = self.navigationController. 

请帮我解决这个问题。 我无法find解决scheme。感谢提前!

ios6您必须使用此方法进行vieworientation

 -(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationMaskAll; } 

并检查我的答案链接