Pat Niemeyer
Pat Niemeyer

Reputation: 6378

iPhone prevent rotation of keyboard to landscape

So, I'm putting some controls over an MPMoviePlayerController and I'm intending this to be used in portrait mode, simply by using video that is shot vertically. My only problem is that for text entry the keyboard comes up in landscape.

Now, I realize that there is an undocumented way to set the orientation of the player, but I'd rather not try this and get rejected at the app store. (FYI this is it):

[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO]; // not legal?

I've tried overriding the autorotate method in my view controller:

   -(BOOL)shouldAutorotateToInterfaceOrientation:   (UIInterfaceOrientation)interfaceOrientation { return NO; }

but it once the movie player starts playing it takes over and doesn't respect this.

I'm just wondering if anyone has any other ideas on a legal way to keep the keyboard in portrait even while the movie player wants to take the system to landscape.

thanks, Pat

Upvotes: 2

Views: 1798

Answers (1)

Chris Ballance
Chris Ballance

Reputation: 34337

When the iPhone is rotated, the "top level" view is sent the notification, and that view is responsible for laying out its subviews.

If your UIWebView is the top level view, it will autorotate itself. However, if you put the UIWebView inside of another view, and have the view controller for that "container" view implement the shouldAutorateToInterfaceOrientation method like this:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return NO;
}

That would probably prevent the UIWebView from knowing the interface was rotated. Note that I haven't actually tried this, but it should would work.


From this SO article

Upvotes: 2

Related Questions