我似乎无法展示我的自定义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
断点指示运行时确实执行代码,甚至捕获图像,但由于某些原因未显示自定义视图控制器。有什么帮助吗?
最佳答案
它是如此愚蠢,花了我一段时间才弄清楚,但是由于某种原因,默认情况下,自定义ShareViewController视图的背景色设置为[UIColor clearColor]。苹果很愚蠢:),但我解决了这种情况
关于ios - iOS分享扩展未显示我的自定义ShareViewController,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37326643/