gpt4 book ai didi

uipopovercontroller - 如何在 iOS 8 中执行 "actionSheet showFromRect"?

转载 作者:行者123 更新时间:2023-12-04 22:12:24 29 4
gpt4 key购买 nike

在 iOS 7 中,我通过“showFromRect”显示 actionSheet:

[actionSheet showFromRect:rect inView:view animated:YES];

但在 iOS 8 中,这不起作用。他们替换了实现并建议我们使用 UIAlertController。那么我如何像弹出框一样显示这个 actionSheet 呢?

最佳答案

使用 UIAlertController 您可以访问 popoverPresentationController 属性来设置 sourceView(又名 inView)和 sourceRect(又名 fromRect)。这与之前的 showFromRect:inView 具有相同的外观:

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleActionSheet];

// Set the sourceView.
alert.popoverPresentationController.sourceView = self.mySubView;

// Set the sourceRect.
alert.popoverPresentationController.sourceRect = CGRectMake(50, 50, 10, 10);

// Create and add an Action.
UIAlertAction *anAction = [UIAlertAction actionWithTitle:@"Action Title" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
NSLog(@"Action Pressed");
}];

[alert addAction:anAction];

// Show the Alert.
[self presentViewController:alert animated:YES completion:nil];

关于uipopovercontroller - 如何在 iOS 8 中执行 "actionSheet showFromRect"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25173682/

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