在菜单视图

时间:2016-01-20 07:34:33

标签: ios uiactivityviewcontroller uiactivity

我对UIActivity功能有疑问。

首先,我创建了3个活动项目:

  1. activityDownload
  2. activityTrash
  3. activityMove
  4. 并添加到UIActivityViewController 然后,当我提出UIActivityViewController时,其中包含3个项目。好的,这里没问题。 然后,当我点击按钮更多,然后对项目进行排序时,我移动"移动"按钮到顶部, 点击"完成"按钮,我不知道为什么下载,垃圾邮件丢失了? 移动项目仅显示在AirDrop菜单视图中。

    NSURL *url = [self fileToURL:self.documentName];
    NSArray *objectsToShare = @[url];
    
    AirDropActivityView *activityDownload = [[AirDropActivityView alloc] init];
    activityDownload.airDropType = 0;
    AirDropActivityView *activityTrash = [[AirDropActivityView alloc] init];
    activityTrash.airDropType = 1;
    AirDropActivityView *activityMove = [[AirDropActivityView alloc] init];
    activityMove.airDropType = 2;
    
    NSArray *uiActivitys = @[activityDownload,activityTrash,activityMove];
    UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:uiActivitys];
    
    // Exclude all activities except AirDrop.
    NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook, UIActivityTypePostToWeibo,UIActivityTypeMessage,UIActivityTypePrint, UIActivityTypeCopyToPasteboard UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,UIActivityTypePostToVimeo,UIActivityTypePostToTencentWeibo];
    controller.excludedActivityTypes = excludedActivities;
    
    // Present the controller
    [self presentViewController:controller animated:YES completion:nil];
    

    https://gist.github.com/tranhieutt/f73999234339f31aa86c

    请看屏幕截图:

    enter image description here

    enter image description here

1 个答案:

答案 0 :(得分:1)

这可能是您正在使用的所有自定义UIActivity视图,具有相同的activityType会导致此问题。

因此,我建议您为要使用的每个视图再创建一个自定义UIActivity。像这样:

创建AirDropActivityView1; 在AirDropActivityView1.m中,执行:

#import "AirDropActivityView1.h"

@implementation AirDropActivityView

- (NSString *)activityType
{
    return @"youapp.Activity1";
}

- (NSString *)activityTitle
{
    return @"Activity1";
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
    return YES;
}

@end

使用AirDropActivityView2.m

    #import "AirDropActivityView2.h"

    @implementation AirDropActivityView

    - (NSString *)activityType
    {
        return @"youapp.Activity2";
    }

    - (NSString *)activityTitle
    {
        return @"Activity2";
    }

    - (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
    {
        return YES;
    }

    @end

最后:

    AirDropActivityView1 *activity1 = [[AirDropActivityView1 alloc] init];

    AirDropActivityView2 *activity2 = [[AirDropActivityView2 alloc] init];

    NSArray *uiActivitys = @[activity1,activity2];

现在您可以重新排序它们。 希望这有帮助。