iPad的presentModalViewController出现在错误的位置

发布于 2024-12-03 07:08:57 字数 1216 浏览 0 评论 0原文

首先,我感觉苹果真的不喜欢我们优化应用程序的横向视图。

在与我的应用程序斗争了 2 天后,我终于说服它始终且仅以横向模式显示。我什至说服了我与presentModalViewController一起呈现的UIViewController也出现在横向中。到目前为止一切顺利...

我用 UIModalPresentationFormSheet 呈现的 UIViewController 的位置一直到右下角(ipad 处于横向位置)。我无法让它像应有的那样移动到中心。有谁知道为什么和/或如何工作以及我如何让它出现在正确的位置?

编辑:添加代码,按下按钮时从 UIViewController 调用此代码。

- (void) buttonPushed
{
    pickerViewController = [[UIViewController alloc] init];
    [pickerViewController.view setBackgroundColor:[UIColor whiteColor]];


    _pickerCustomers = [[UIPickerView alloc] initWithFrame:CGRectMake(22,20,380,216)];
    _pickerCustomers.delegate = self;
    _pickerCustomers.dataSource = self;
    [_pickerCustomers setShowsSelectionIndicator:YES];
    [pickerViewController.view addSubview:_pickerCustomers];

    _btnPickerDone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_btnPickerDone setFrame: CGRectMake(300,250,98,45)];
    [_btnPickerDone setTitle:@"Select" forState:UIControlStateNormal];
    [pickerViewController.view addSubview:_btnPickerDone];

    pickerViewController.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:pickerViewController animated:YES];
}

First of, I get the feeling apple really doesnt like us optimizing apps for landscape view.

After struggling with my app for 2 days I finally convince it to always and only show in Landscape mode. I even convinced the UIViewController that I present with presentModalViewController to appear in landscape as well. So far so good...

The position of the UIViewController that I present with UIModalPresentationFormSheet is all the way to the bottom right (with the ipad in Landscape positition). I cannot get it to move to the center like it should. Does anyone have any ideas why and or how this works and how I can make it apear in the right position?

EDIT: Added code, this code is called from a UIViewController when a button is pushed.

- (void) buttonPushed
{
    pickerViewController = [[UIViewController alloc] init];
    [pickerViewController.view setBackgroundColor:[UIColor whiteColor]];


    _pickerCustomers = [[UIPickerView alloc] initWithFrame:CGRectMake(22,20,380,216)];
    _pickerCustomers.delegate = self;
    _pickerCustomers.dataSource = self;
    [_pickerCustomers setShowsSelectionIndicator:YES];
    [pickerViewController.view addSubview:_pickerCustomers];

    _btnPickerDone = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [_btnPickerDone setFrame: CGRectMake(300,250,98,45)];
    [_btnPickerDone setTitle:@"Select" forState:UIControlStateNormal];
    [pickerViewController.view addSubview:_btnPickerDone];

    pickerViewController.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:pickerViewController animated:YES];
}

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

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

发布评论

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

评论(1

凉月流沐 2024-12-10 07:08:57

您是否尝试过使用布局 IB 上的小“自动定位弹簧”?也许您将其固定在底部和右侧,只需删除这些附件即可。

这是给您的链接: http://disanji.net/ iOS_Doc/#documentation/DeveloperTools/Conceptual/IB_UserGuide/Layout/Layout.html

如果您愿意,也可以在代码中完成。

Have you tried playing with the little "autoposition springs" on the layout IB? Probably you have it attached to the bottom and right, simply remove those attachments.

Here's a link for you: http://disanji.net/iOS_Doc/#documentation/DeveloperTools/Conceptual/IB_UserGuide/Layout/Layout.html

Can also be done in code if you like.

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