【问题标题】:UISplitViewController detailViewController subviews not resizing properly on orientation changeUISplitViewController detailViewController 子视图在方向更改时未正确调整大小
【发布时间】:2023-03-16 09:21:01
【问题描述】:

嗨, 我的 iPad 应用程序中有以下设置:

UISplitViewController 详情-> SomeDetailViewController-> 添加子视图为 [SomeDetailViewController.view addSubview:AnotherViewController.view]

  1. 现在在显示“AnotherViewController 视图”时启动后,其初始尺寸始终与上一个方向相同(界面生成器中的纵向/横向视图)我保存了该视图 XIB,而与当前设备方向无关.

  2. 还重置添加的子视图的框架(AnotherViewController.view),即 A. 在 -[SomeDetailViewController viewDidLoad] 检查当前设备方向 B. 设置 AnotherViewController.view 的框架以匹配所需的大小.此后它不会在方向更改时适当调整大小(我在 XIB 自动调整大小框中正确设置了弹簧/支柱)。

  3. 在执行上述第 2 步之后,我确实看到底部的大约一半的 AnotherViewController.view 没有响应任何触摸,看起来由于帧的变化,响应坐标变得混乱。

  4. 我确实实现了“shouldAutorotateToInterfaceOrientation”,以便为我的所有视图控制器中的所有方向返回 YES。

TIA。

【问题讨论】:

    标签: ipad uisplitviewcontroller


    【解决方案1】:

    在 XIB 中将有一个选项来更改 Inspector 中的 SPlitview Detail/Master。此外,如果您将其添加为子视图,您将无法获得 splitview 委托方法,因为您需要将其添加到窗口。尝试使用

    从窗口中删除所有元素

    [[[[UIAppDelegate 窗口] 子视图] objectAtIndex:0] removeFromSuperview]; self.appDelegate.splitViewControllerObject = [[UISplitViewController alloc] init];

    UINavigationController *rootNav = [[UINavigationController alloc]initWithRootViewController:masterview]; UINavigationController *detailNav = [[UINavigationController alloc]initWithRootViewController:detailview];

        self.appDelegate.splitViewControllerObject.viewControllers = [NSArray arrayWithObjects:rootNav, detailNav, nil];
        self.appDelegate.splitViewControllerObject.delegate = detailviewobj;
    
        [UIAppDelegate.window addSubview:self.appDelegate.splitViewControllerObject.view];
    

    祝你好运……

    【讨论】:

      【解决方案2】:

      您应该将 autoresize 属性设置为 AnotherViewController.view:

      AnotherViewController.view.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-11-02
        • 2013-05-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-22
        相关资源
        最近更新 更多