我似乎无法展示我的自定义 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)viewWillAppearBOOL)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)viewDidAppearBOOL)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 dataWithContentsOfURLNSURL*)item]];
}
if([(NSObject*)item isKindOfClass:[UIImage class]])
{
sharedImage = (UIImage*)item;
}
}];
}
}
}
@end
Breakpoint 表示运行时确实执行代码,甚至抓取图像,但由于某种原因没有呈现自定义 View Controller 。有什么帮助吗?
Best Answer-推荐答案 strong>
这太愚蠢了,我花了一段时间才弄明白,但由于某种原因,默认情况下,自定义 ShareViewController View 的背景颜色设置为 [UIColor clearColor]。非常愚蠢的苹果,但我解决了这个案子
关于iOS 共享扩展未显示我的自定义 ShareViewController,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/37326643/
|