问题
SLComposeViewController
takes 3-4 seconds to appear after presenting it. But presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion
methods completion block gets called immediately. So even if I use a loading indicator it disappears in a blink. The related code is below. Btw I tried dispatch_async
it didn't work.
How can I speed up the process do you have any ideas?
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:
So, this isn't a fix, but it might help you out. I couldn't get the thing to appear faster, I think its just the implementation pulling in data before displaying itself.
Since the presentViewController completion executes almost instantly, my workaround was to display a progress view, and set a selector to execute after 2 seconds. The selector simply hides the progress view, here's an example.
[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];
}
来源:https://stackoverflow.com/questions/30124517/slcomposeviewcontroller-appears-slowly