UIActivity activityViewController在iPad上以模态方式呈现,而不是在popover中呈现 [英] UIActivity activityViewController being presented modally on iPad instead of in popover

查看:149
本文介绍了UIActivity activityViewController在iPad上以模态方式呈现,而不是在popover中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When using a customer UIActivity subclass in iOS 6, it's possible to specify a custom view controller that will be displayed when your action is chosen from the initial UIActionViewController's view. You do this by returning a reference to a custom view controller from your UIActivity subclass's activityViewController method.

根据 UIActivity类参考


activityViewController

此方法的默认实现返回。使用视图控制器提供附加UI的子类可以重写此方法以返回该视图控制器。如果此方法返回有效对象,系统将为您显示返回的视图控制器,而不是调用 performActivity 方法。在iPad上,您的视图控制器显示在弹出窗口内。在iPhone和iPod touch上,视图控制器以模态显示。

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.

您的自定义视图控制器应提供自定义UI的视图,并应处理这些视图中的任何用户交互。完成活动后,请勿自行关闭视图控制器。相反,请调用 activityDidFinish:方法,让系统为您解雇。

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上,视图控制器显示在弹出框内。在iPhone和iPod touch上,视图控制器以模态显示。

但是,在iPad上,视图控制器由 activityViewController返回总是以模态方式显示,无论我如何呈现UIActivityViewController(无论是模态还是通过弹出框)。当通过弹出窗口呈现时,它会导致崩溃,因为它认为它没有被解雇。

However, on iPad the view controller returned by activityViewController always displays modally, no matter how I present the UIActivityViewController (either modally or via a popover). When presenting via a popover, it causes it to crash since it doesn't think it's been dismissed.

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

What am I doing wrong? Is this a bug in iOS 6?

更新:这是一个简单的Xcode项目,用于说明问题。随意克隆它并玩游戏,看看你是否能看到我们出错的地方: github.com/simonwhitaker/GSActivityDemo

Update: here's a simple Xcode project that illustrates the problem. Feel free to clone it and play around to see if you can see where we're going wrong: github.com/simonwhitaker/GSActivityDemo

推荐答案

正如我们所说的UIActivityViewController,它是向用户显示可用活动的视图。 Apple说明以下内容......

As we are talking about the UIActivityViewController, which is the view showing the available activities to the user. Apple state the following...


您的应用程序负责配置,显示和解除此视图控制器。视图控制器的配置涉及指定视图控制器应该在其上操作的数据对象。 (您还可以指定应用程序支持的自定义服务列表。)在呈现视图控制器时,必须使用适用于当前设备的方法。在iPad上,您必须在弹出窗口中显示视图控制器。在iPhone和iPod touch上,你必须以模态方式呈现它。

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.

我把最后一行作为一个标志,你必须处理如何显示视图,因此我检查代码是否在iPad上运行并相应地使用UIPopover。正如你可以在这里... https://github.com/bufferapp/ buffer-uiactivity / blob / master / BufferUIActivity / Views / FirstViewController.m 在以下方法中。

I took the last line as a sign that you have to handle how the view is presented, so I check whether the code is running on iPad and use a UIPopover accordingly. As you can sere here... https://github.com/bufferapp/buffer-uiactivity/blob/master/BufferUIActivity/Views/FirstViewController.m within the following method.

-(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];
    }

}

这篇关于UIActivity activityViewController在iPad上以模态方式呈现,而不是在popover中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆