【问题标题】:modalViewController presented from UISplitViewController comes up as the wrong orientation从 UISplitViewController 呈现的 modalViewController 出现方向错误
【发布时间】:2012-07-19 19:35:51
【问题描述】:

我有一个UISplitViewController,它设置在我的应用程序的 rootView 中。当在我的左视图控制器中调用 viewDidLoad 时,我会进行检查,然后使用以下内容显示模态视图控制器:

SiteConfiguration *config = [[SiteConfiguration alloc] initWithStyle:UITableViewStyleGrouped];
config.firstLoad = YES;
UINavigationController *configNav = [[UINavigationController alloc] initWithRootViewController:config];
if ([Utility isIpad]) {
    configNav.modalPresentationStyle = UIModalPresentationFormSheet;
    configNav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [[AppDelegate instance].splitViewController presentModalViewController:configNav animated:YES];
} else {
    [self presentModalViewController:configNav animated:YES];
}

如果 iPad 在应用加载时处于横向模式,则 modalView 显示的方向不正确:

我可以旋转 iPad 来解决这个问题,但为什么加载错误?我有shouldAutorotateToInterfaceOrientation: 在我的SiteConfiguration viewController 中返回YES。这可能是什么原因造成的?

【问题讨论】:

    标签: objective-c ios cocoa-touch uisplitviewcontroller modalviewcontroller


    【解决方案1】:

    请注意您选择展示模态控制器的位置。 我有一些自定义模态控制器的经验,并在

    中设置模态控制器的方向(及其阴影!)
     - (void)viewDidLoad:(BOOL)animated 

    并不总是按预期运行。

    将您的代码 (presentModalViewController:configNav animated:YES) 放入

     - (void)viewDidAppear:(BOOL)animated

    相反。 (对于设置子视图框架或对图层进行任何操作的任何代码,例如阴影图层和阴影属性,也可以这样做)。

    据我所知,在旋转视图的子视图之前,旋转可能不明显

     - (void)viewDidLoad:(BOOL)animated 
    由于线程问题(一个线程可能会在主线程将旋转传递给子视图(和模态控制器)之前开始绘制您的子视图或模态控制器的视图)。比我有更多线程经验的人可能会对此有所了解。

    【讨论】:

    • 哎呀,我的意思是输入viewDidAppear:。我已经适当地编辑了我的答案
    【解决方案2】:

    shouldAutorotateToInterfaceOrientation: 实际上并没有旋转界面,应用程序在收到UIDeviceOrientationDidChangeNotification 通知时会这样做。

    尝试在-(void) viewDidAppear:(BOOL)animated 方法中添加对设备方向的检查。

    要强制界面旋转,请使用以下代码。

    UIDeviceOrientation toInterfaceOrientation = [[UIDevice currentDevice] orientation];
    [UIApplication sharedApplication].statusBarOrientation = toInterfaceOrientation;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-05
      • 1970-01-01
      相关资源
      最近更新 更多