gpt4 book ai didi

ios - UIActivity activityViewController 以模态方式呈现在 iPad 上而不是弹出窗口中

转载 作者:技术小花猫 更新时间:2023-10-29 10:21:40 27 4
gpt4 key购买 nike

在 iOS 6 中使用客户 UIActivity 子类时,可以指定一个自定义 View Controller ,当您从初始 UIActionViewController 的 View 中选择您的操作时将显示该 View Controller 。您可以通过从 UIActivity 子类的 activityViewController 方法返回对自定义 View Controller 的引用来执行此操作。

根据UIActivity class reference :

activityViewController

The default implementation of this method returns nil. Subclasses that provide additional UI using a view controller can override this method to return that view controller. If this method returns a valid object, the system presents the returned view controller for you, instead of calling the performActivity method. On iPad, your view controller is presented inside of a popover. On iPhone and iPod touch, your view controller is presented modally.

Your custom view controller should provide a view with your custom UI and should handle any user interactions inside those views. Upon completing the activity, do not dismiss the view controller yourself. Instead, call the activityDidFinish: method and let the system dismiss it for you.

请注意第一段末尾的那一点:在 iPad 上,您的 View Controller 显示在弹出框内。在 iPhone 和 iPod touch 上,您的 View Controller 以模态方式呈现。

但是,在 iPad 上,activityViewController 返回的 View Controller 始终以模态显示,无论我如何呈现 UIActivityViewController(模态或通过弹出窗口)。当通过弹出窗口呈现时,它会导致崩溃,因为它认为它没有被关闭。

我做错了什么?这是 iOS 6 中的错误吗?


更新:这里有一个简单的 Xcode 项目可以说明问题。随意克隆它并尝试看看你是否能看出我们哪里出错了:github.com/simonwhitaker/GSActivityDemo

最佳答案

因为我们正在谈论 UIActivityViewController,它是向用户显示可用事件的 View 。 Apple 声明如下...

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.

我将最后一行作为您必须处理 View 呈现方式的标志,因此我检查代码是否在 iPad 上运行并相应地使用 UIPopover。正如您在这里看到的... https://github.com/bufferapp/buffer-uiactivity/blob/master/BufferUIActivity/Views/FirstViewController.m在以下方法中。

-(IBAction)openUIActivityView:(id)sender {

NSString *text = @"Hello world";
NSString *url = @"http://bufferapp.com";


NSArray *activityItems = @[text, url];

BufferUIActivity *bufferActivity = [[BufferUIActivity alloc] init];

UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[ bufferActivity ]];


if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
[self presentViewController:activityView animated:YES completion:^{

}];
} else {
// Change Rect to position Popover
self.popup = [[UIPopoverController alloc] initWithContentViewController:activityView];
[self.popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.width/2, 100, 100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

}

关于ios - UIActivity activityViewController 以模态方式呈现在 iPad 上而不是弹出窗口中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13433718/

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