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];
}];发布于 2016-08-16 07:04:20
所以,这不是一个解决办法,但它可能会帮助你。我不能让这个东西更快的出现,我想它只是实现在显示之前拉入数据。
由于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];
}https://stackoverflow.com/questions/30124517
复制相似问题