ios – UIActivity activityViewController被模拟地呈现在iPad上,而不是popover

在iOS 6中使用客户UIActivity子类时,可以指定一个自定义视图控制器,当您从最初的UIActionViewController视图中选择您的操作时,该控件将显示.您可以从UIActivity子类的activityViewController方法返回对自定义视图控制器的引用.

根据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上,您的视图控制器显示在popover内.在iPhone和iPod touch上,您的视图控制器以模态显示.

然而,在iPad上,由activityViewController返回的视图控制器总是以模态方式显示,无论我如何呈现UIActivityViewController(通过模态或通过popover).当通过popover呈现时,它会导致它崩溃,因为它不认为它被解雇.

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

更新:这是一个简单的Xcode项目,说明了这个问题.随意克隆它,玩耍,看看你能不能看到我们错在哪里:github.com/simonwhitaker/GSActivityDemo

解决方法

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

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在以下的方法.

-(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上,而不是popover全部内容,希望文章能够帮你解决ios – UIActivity activityViewController被模拟地呈现在iPad上,而不是popover所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。