gpt4 book ai didi

uipopovercontroller - 在 iOS8 : UIPopoverController presentPopoverFromRect not work for keyWindow any more

转载 作者:行者123 更新时间:2023-12-03 15:02:55 24 4
gpt4 key购买 nike

如上所述,在 iOS8 中,[UIPopoverController presentPopoverFromRect] 不再适用于 [UIApplication sharedApplication].keyWindow。 (它确实适用于 iOS7)

我验证了以下代码:

TestViewController *test = [[TestViewController alloc] initWithNibName:nil bundle:nil];

if (testPopoverController == nil) {
testPopoverController = [[UIPopoverController alloc] initWithContentViewController:test];
testPopoverController.popoverContentSize = CGSizeMake(250, 95*5);


}

CGPoint point = [sender convertPoint:CGPointMake(0, 0) toView:nil];
CGRect rect = CGRectMake(point.x, point.y, 24, 24);

[testPopoverController presentPopoverFromRect:rect inView:[UIApplication sharedApplication].keyWindow permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

最佳答案

我想出的最佳解决方案是有条件地处理它。如果在 iOS 7 上,请使用我们在关键窗口上显示 UIPopoverController 的工作代码。如果在 iOS 8 上,请使用以下命令:

     viewController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *presentationController = viewController.popoverPresentationController;
[presentationController setDelegate:self];
presentationController.permittedArrowDirections = 0;
presentationController.sourceView = [[UIApplication sharedApplication] keyWindow];
presentationController.sourceRect = [[UIApplication sharedApplication] keyWindow].bounds;

[viewController setPreferredContentSize:CGSizeMake(320, 480)];
[parentController presentViewController:viewController animated:YES completion:nil];

这最终与以下功能相同:
     self.popoverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
[self.popoverController setDelegate:self];
[self.popoverController setPopoverContentSize:isLandscape() ? CGSizeMake(480*2, 320*2) : CGSizeMake(320*2, 480*2)];
[self.padPopover presentPopoverFromRect:CGSizeMake(320, 480)
inView:[[UIApplication sharedApplication] keyWindow]
permittedArrowDirections:0
animated:YES];

关于uipopovercontroller - 在 iOS8 : UIPopoverController presentPopoverFromRect not work for keyWindow any more,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24976741/

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