【问题标题】:iOS Share Extension not presenting my custom ShareViewControlleriOS 共享扩展未显示我的自定义 ShareViewController
【发布时间】:2016-09-16 12:51:27
【问题描述】:

我似乎无法展示我的自定义 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

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

【问题讨论】:

    标签: ios objective-c share


    【解决方案1】:

    这太愚蠢了,我花了一段时间才弄明白,但由于某种原因,默认情况下,自定义 ShareViewController 视图的背景颜色设置为 [UIColor clearColor]。非常愚蠢的苹果:),但我解决了这个案子

    【讨论】:

    • 因此我认为:self.view.alpha = 0;
    • 是的,我从某个人那里复制了一些代码,甚至没有注意到 xD
    • :D 也经常是我的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多