SLComposeViewController缓慢显示

时间:2015-05-08 12:58:42

标签: ios objective-c slcomposeviewcontroller

出现后,

SLComposeViewController需要3-4秒才能显示。但是presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion方法立即调用完成块。因此,即使我使用加载指示器,它也会在眨眼间消失。相关代码如下。顺便说一下,我试过dispatch_async它不起作用。

如果您有任何想法,我怎样才能加快这个过程?

SLComposeViewController *shareView = [SLComposeViewController composeViewControllerForServiceType: SLServiceTypeFacebook];
[shareView setTitle:@"Title"];
[shareView setInitialText:@"Description"];
[shareView addURL:[NSURL URLWithString:@"http://www.google.com/"]];
[shareView setCompletionHandler:^(SLComposeViewControllerResult result) {

    switch (result) {
        case SLComposeViewControllerResultCancelled:
        {
            NSLog(@"Facebook Post Canceled");
            break;
        }
        case SLComposeViewControllerResultDone:
        {
            NSLog(@"Facebook Post Successful");
            break;
        }
        default:
            break;
    }
}];

UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center = CGPointMake([UIScreen mainScreen].bounds.size.width / 2.0, [UIScreen mainScreen].bounds.size.height / 2.0);
[activityView startAnimating];
[self.view addSubview:activityView];

[self presentViewController:shareView animated:YES completion:^{
    NSLog(@"Presented facebook");
    [activityView removeFromSuperview];
}];

1 个答案:

答案 0 :(得分:0)

所以,这不是一个修复,但它可能会帮助你。我无法让事情看起来更快,我认为它只是在显示自己之前拉入数据的实现。

由于presentViewController几乎立即执行,我的解决方法是显示进度视图,并设置一个选择器在2秒后执行。选择器只是隐藏进度视图,这是一个例子。

[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self performSelector:@selector(hideProgressView) withObject:nil afterDelay:2.0f];

[self presentViewController:self.composeViewController animated:YES completion:nil];


- (void)hideProgressView
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
}