[ self presentModalViewController: controller animated: YES ]; Behaves strangely

徘徊边缘 提交于 2020-01-17 01:24:11

问题


I have an Universal App that supports all orientations in iPad and only potrait in iPhone / iPod. My code looks somewhat like this:

@implementation UIViewController ( interfaceOrientationHack )
  - (void) shouldAutorotateToInterfaceOrientation: ( UIInterfaceOrientation ) toInterfaceOrientation {
    if( iPad ) {
      return YES;
    } else if( toInterfaceOrientation == UIInterfaceOrientationPotrait ) { 
      return YES;
    } else return NO;
  }
@end

From one of my controllers, i launch a navigation controller as modal view controller

[ self presentModalViewController: c animated: YES ];

The issue currently is, the modal controller launches correctly in orientation, But when i change my orientation the the modal controller doesn't change its orientation, all the rest of the controllers behave correctly.

Any help will be hugely appreciated. Thanks in advance.


回答1:


From UIViewcontroller class reference:"By default, the UIViewController class displays views in portrait mode only. To support additional orientations, you must override the shouldAutorotateToInterfaceOrientation: method and return YES for any orientations your subclass supports. If the autoresizing properties of your views are configured correctly, that may be all you have to do."

Since your modal view inherits from UIViewcontroller, you have to override shouldAutorotateToInterfaceOrientation:in your modal view.



来源:https://stackoverflow.com/questions/5262868/self-presentmodalviewcontroller-controller-animated-yes-behaves-strangely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!