gpt4 book ai didi

iOS:Autolayout 和 popOverController 问题(可能是 Xcode 错误)

转载 作者:行者123 更新时间:2023-11-28 21:21:27 24 4
gpt4 key购买 nike

我在下面的代码中为 iPhone 和 iPad 显示了我的 popOverController

 ViewController *vc = [[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];

if ([UIDevice currentDevice].userInterfaceIdiom ==
UIUserInterfaceIdiomPad) {
vc.preferredContentSize = CGSizeMake(296, 476); //your custom size.
} else {
vc.preferredContentSize = CGSizeMake(252, 436.5);
}

vc.modalPresentationStyle = UIModalPresentationPopover;
vc.popoverPresentationController.delegate = self;
vc.popoverPresentationController.sourceView = self.view;
vc.popoverPresentationController.sourceRect = CGRectMake(screenWidth / 2, self.view.height / 2, 1, 1);

[self presentViewController:vc animated:YES completion:nil];

UIPopoverPresentationController *popOverController = vc.popoverPresentationController;
popOverController.permittedArrowDirections = 0;

但是,似乎出现了类(class)规模问题。即使在运行 iPad 设备时,似乎正在使用 iPhone 尺寸而不是 iPad 尺寸。尽管在 Interface Builder 中,它会根据所选设备显示两种不同大小的按钮。

编辑:例如,我有一个带有按钮的 viewcontroller.xib。根据实际设备,有两种不同的按钮大小。在 iPhone 上,按钮的尺寸为 50 x 50。在 iPad 上,按钮的尺寸为 430 x 430。在界面生成器中,这显示正确。但是,当运行 iPad 设备时,按钮显示为 50 x 50,而它应该是 430 x 430。

最佳答案

Storyboard中的条件约束使用大小类

iPad 上弹出窗口呈现的 View Controller 的水平尺寸类是 Compact,就像在 iPhone 上一样。这就是为什么您会看到按钮的 iPhone 尺寸。

要证明这是真的,请将 ViewController 类中的 viewDidAppear: 重写为 NSLog self.traitCollection。您会看到水平大小类是紧凑的。

这是有道理的,因为弹出窗口就像出现在 iPad 上的 iPhone 大小的窗口。事实上,这就是弹出窗口的全部

关于iOS:Autolayout 和 popOverController 问题(可能是 Xcode 错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39671490/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com