开发者

iOS prevent rotation in certain views

I have a viewcontroller and its view that support only landscape in iPad.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == UIInterfaceOrientationPortrait)
    return NO;
else
    return YES;

}

But I have a view with a movie player that needs to be in portrait only. So in this view I do this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

if (interfaceOrientation == U开发者_如何学PythonIInterfaceOrientationPortrait)
    return YES;
else
    return NO;
}

My problem is that if I, in the first viewcontroller set portrait to NO, then my second view controller will never rotate to portrait. The secondviewcontroller is added as a subview of the first. How can I get view 1 to not rotate to portrait, but get view 2 to not rotate to landscape. This app is for demo purposes so really i'm just looking for the technical answer on this one.


I do not believe this is possible when adding as a subview. Try pushing the new view onto an invisible UINavigationController stack to accomplish your goal. This will work when going from the first view to the second, but it is very tricky to get the first view to rotate back to its original position when the 2nd vc is popped because apple does not want you doing this. Here's a very very hacky trick to force it back on pop:

-(void)viewDidAppear:(BOOL)animated {   
    UIViewController *c = [[UIViewController alloc] init];
    [self presentModalViewController:c animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [c release];    
}


When I have encountered this problem in the past, I have done this:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   if(mayRotate){
      return YES;
   }else{
      return NO;
   }
}

I think there's a little more to it, but you should have the idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜