iOS 模式弹出窗口横向定位错误?

发布于 2024-10-08 00:59:31 字数 730 浏览 0 评论 0原文

我在从横向呈现模态视图时遇到奇怪的问题。只需从一个新的基于视图的应用程序开始并执行以下操作即可重现该问题:

  1. 创建一个将要呈现的新 UIViewController 子类。我将我的命名为 ModalViewController。更改视图背景颜色以使错误更加明显。

  2. return YES; 在两个控制器中 shouldAutorotateToInterfaceOrientation:

  3. IBAction 添加到主视图以显示模式,并将此操作挂接到主视图控制器中的按钮。

    <前><代码>- (IBAction)showModal { ModalViewController *vc = [[ModalViewController alloc] initWithNibName:@"ModalViewController" 包:nil]; [自我呈现ModalViewController:vc动画:否]; [vc发布]; }

现在,当您在横向模式下单击按钮时,您应该会看到问题。整个视图向上并向左移动。

其他人遇到这个问题或有任何解决方法吗?我在 iPad 上也遇到类似的问题。

替代文本

I am having strange problems presenting modal views from landscape orientation. The problem can be recreated by simply starting with a new view-based application and doing the following:

  1. Create a new UIViewController subclass that will be presented. I named mine ModalViewController. Change the views background color to make the bug more noticeable.

  2. return YES; in both controllers shouldAutorotateToInterfaceOrientation:

  3. Add an IBAction to your main view to display the modal and hook this action up to a button in your main view controller.

    - (IBAction)showModal {  
      ModalViewController *vc = [[ModalViewController alloc] initWithNibName:@"ModalViewController" bundle:nil];  
      [self presentModalViewController:vc animated:NO];  
      [vc release];  
    }
    

Now when you click the button from landscape mode you should see the problem. The entire view is shifted up and to the left.

Anyone else experiencing this problem or have any workarounds? I am having similar problems on the iPad.

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

马蹄踏│碎落叶 2024-10-15 00:59:31

在注意到视图在 viewDidAppear 中具有正确的框架并且稍后被搞乱后,我最终通过在 ModalViewController 中实现以下内容来修复此问题。这假设有一个名为 frame_CGRect 实例变量。

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  frame_ = [[self view] frame];
  [self performSelector:@selector(fixFrame) withObject:nil afterDelay:0];
}

- (void)fixFrame {
  [[self view] setFrame:frame_];
}

我想说这是一个错误。

After noticing the view had the correct frame in viewDidAppear and was being messed up sometime later I ended up fixing this by implementing the following in ModalViewController. This assumes a CGRect instance variable named frame_.

- (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  frame_ = [[self view] frame];
  [self performSelector:@selector(fixFrame) withObject:nil afterDelay:0];
}

- (void)fixFrame {
  [[self view] setFrame:frame_];
}

I would say this is a bug.

俯瞰星空 2024-10-15 00:59:31
  [self presentModalViewController:vc animated:YES];  

不要禁用动画,而是尝试启用动画。

  [self presentModalViewController:vc animated:YES];  

Instead of disabling animation, Try enabling the animation.

野心澎湃 2024-10-15 00:59:31

什么自动调整大小蒙版吗? (您将在 XIB 文件中进行设置。)它看起来没有附加到屏幕的右侧。

另外,您的视图是否考虑了状态栏的大小? (我注意到底部的间隙看起来与状态栏的大小非常相似。)

您可以通过按视图标题栏上的箭头在 Interface Builder 中模拟很多这样的情况。

What autoresizing mask are you using? (You'll be setting this in the XIB file.) It looks like it's not attached to the right side of the screen.

Also, is your view taking into account the size of the status bar? (I note the gap at the bottom looks very similar in size to the status bar.)

You can simulate a lot of this in Interface Builder by pressing the arrow on the title bar of the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文