开发者

shouldAutorotateToInterfaceOrientation not being called iphone

So i'm trying to make some view rotate but the method is not even called and i'm so frustrated. Here is the method:

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

I also tried:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return ((interfaceOrientation == UIInterfac开发者_C百科eOrientationPortrait) ||
            (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}

My info.plist looks like this:

shouldAutorotateToInterfaceOrientation not being called iphone

What i'm i missing ? I've looked at all the answers i found here in SO but still the problem remains.


Possibly you need specify also portrait orientation as supported in your info.plist. (Actually it is possible that also removing those orientation keys entirely will do).

By the way: which kind of app are you building? do you use a tab bar or navigation controller (they have specific restrictions for orientation change)?

EDIT:

for a tab bar controller, it is required that all controllers managed by it support a given orientation for autorotation to work.


This only works if you subclass your own UIViewController. Apple's default implementation returns NO for all these values except for UIInterfaceOrientationPortrait (obviously). So create a new file, make it a subclass of UIViewController, go to its .m file and paste this in:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES; //that's enough
}

Then use this subclass as your view controller and the rotation will work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜