开发者

iPhone SDK: Forcing landscape mode for a single part of an app

开发者 https://www.devze.com 2022-12-17 16:45 出处:网络
Yet another landscape mode question. We\'ve all seen the [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

Yet another landscape mode question.

We've all seen the

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

Nonsense. I have not been able to get 开发者_如何学Cthis to work on the simulator or on the device.

What I get is this:

http://i47.tinypic.com/zl9egh.png

when I really want this:

http://i45.tinypic.com/xms6cm.png

As you might be able to tell, it's flipping the phone but it's not realizing it has been flipped.

I've seen the hidden method

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

But I need this app to be on the app store, and I don't know if they will crack down on that.

Does anyone have any idea on how to get this damn thing to straighten itself out?


Ideally your view controller should implement:

- (BOOL)shouldAutorotateToInterfaceOrientation:
                         (UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
                 interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

Then the only allowed orientation for that view controller is one of the landscape orientations.

Unless you have a pretty complex view hierarchy that utilizes a tab bar controller, this should cause the view to rotate when it's pushed.

If it doesn't work you can try:

[[UIDevice currentDevice] performSelector:
                               @selector(setOrientation:) 
                           withObject:(id)UIInterfaceOrientationLandscapeRight];

I have an app in the AppStore that uses this code because in my case I do have a complex hierarchy of views that keeps the one I need to be landscape only from working.


If you want to rotate a single part of the app you can use the CGAffineTransform transform property of a UIView. For an example check this thread:

How do I apply a perspective transform to a UIView?

0

精彩评论

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