【问题标题】:Custom Size UIModalPresentationFormSheet returns to default size when keyboard shows自定义大小 UIModalPresentationFormSheet 在键盘显示时返回默认大小
【发布时间】:2018-03-29 14:49:18
【问题描述】:

我正在使用UIModalPresentationFormSheet 显示一个自定义大小的模式,如下所示:

    UIViewController *viewController = [[UIViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
    navController.modalPresentationStyle = UIModalPresentationFormSheet;

我希望这个视图控制器具有我在 viewWillAppear 中设置的自定义大小(它是一个混合的 Objc-Swift 项目):

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    self.navigationController?.view.superview?.bounds = CGRect(x: 0, y: 0, width: 540, height: 350)
}

这个问题是视图控制器有一个 UITextField,当被选中(并且键盘显示)时,模式会调整为默认表单大小。关于如何在键盘显示时保持视图控制器自定义大小的任何建议?

【问题讨论】:

    标签: ios objective-c swift uikit


    【解决方案1】:

    想通了。

    我能够通过在呈现视图控制器之前设置 navController.preferredContentSize 来解决问题,而不是在 viewWillAppear 中修改框架。

    【讨论】:

      猜你喜欢
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多