【发布时间】:2023-03-03 03:46:01
【问题描述】:
我在下面的代码中显示了我的popOverController 用于 iPhone 和 iPad。
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;
但是,似乎出现了班级规模问题。即使在运行 iPad 设备时,似乎使用的是 iPhone 尺寸,而不是 iPad 尺寸。尽管在界面构建器中,它会根据所选设备显示两种不同大小的按钮。
编辑:例如,我有一个带有按钮的 viewcontroller.xib。根据实际设备,有两种不同的按钮尺寸。在 iPhone 上,按钮的尺寸为 50 x 50。在 iPad 上,它的尺寸为 430 x 430。在界面生成器中,这显示正确。但是,在运行 iPad 设备时,按钮显示为 50 x 50,而假设为 430 x 430。
【问题讨论】:
-
“大小”是什么意思?在 iPhone 上,你甚至不会看到弹出框;您将看到一个全屏显示的视图控制器。那么你怎么知道“大小”应该是什么?请显示屏幕截图。
-
例如,我有一个带有按钮的 viewcontroller.xib。根据实际设备,有两种不同的按钮尺寸。在 iPhone 上,按钮的尺寸为 50 x 50。在 iPad 上,它的尺寸为 430 x 430。在界面生成器中,这显示正确。但是,在运行 iPad 设备时,按钮显示为 50 x 50,而假设为 430 x 430。而且我在 iPhone 上也有一个弹出窗口。
-
好的,我明白了。
标签: ios objective-c autolayout xib popover