iOS Share Extension不呈现我的自定义ShareViewController

时间:2016-05-19 14:42:40

标签: ios objective-c share

我似乎无法呈现我的自定义ShareViewController。我继承了UIViewController,而不是SLComposeViewController,将它添加到Storyboard,但是当我选择要共享的图像时,不会显示ShareViewController。这是我的整个代码:

标题文件:

#import <UIKit/UIKit.h>
#import <Social/Social.h>

@interface ShareViewController : UIViewController

@end

实施档案:

@implementation ShareViewController

- (void)viewDidLoad{
    [super viewDidLoad];
    self.view.alpha = 0;

}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    self.view.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height);
    [UIView animateWithDuration:0.25 animations:^
     {
         self.view.transform = CGAffineTransformIdentity;
     }];
}

- (void)dismiss
{
    [UIView animateWithDuration:0.20 animations:^
     {
         self.view.transform = CGAffineTransformMakeTranslation(0, self.view.frame.size.height);
     }
                     completion:^(BOOL finished)
     {
         [self.extensionContext completeRequestReturningItems:nil completionHandler:nil];
     }];
}

-(void)viewDidAppear:(BOOL)animated {

    [super viewDidAppear:YES];

    for (NSItemProvider* itemProvider in ((NSExtensionItem*)self.extensionContext.inputItems[0]).attachments )
    {
        if([itemProvider hasItemConformingToTypeIdentifier:@"public.image"])
        {
            [itemProvider loadItemForTypeIdentifier:@"public.image" options:nil completionHandler:
             ^(id<NSSecureCoding> item, NSError *error)
             {
                 UIImage *sharedImage = nil;
                 if([(NSObject*)item isKindOfClass:[NSURL class]])
                 {
                     sharedImage = [UIImage imageWithData:[NSData dataWithContentsOfURL:(NSURL*)item]];


                 }
                 if([(NSObject*)item isKindOfClass:[UIImage class]])
                 {
                     sharedImage = (UIImage*)item;
                 }
             }];
        }
    }
}

@end

断点表示运行时确实执行代码,甚至抓取图像,但自定义视图控制器由于某种原因未显示。有什么帮助吗?

1 个答案:

答案 0 :(得分:3)

这太愚蠢了,我花了一些时间来搞清楚,但出于某种原因,默认情况下,自定义ShareViewController视图的背景颜色设置为[UIColor clearColor]。非常愚蠢的Apple :),但我解决了这个案例