如何使用 SLComposeViewController 更快地制作presentViewController? [英] How to make the presentViewController with SLComposeViewController faster?

查看:35
本文介绍了如何使用 SLComposeViewController 更快地制作presentViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用上打开 Twitter 撰写视图,但屏幕显示时间过长!

I am opening the Twitter compose view on my app, but the screen takes too long to be displayed!

当用户点击 Twitter 按钮时,我开始使用以下代码:

I started using the following code when the user taps the twitter button:

 if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{

    SLComposeViewController *tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

    [tweet setInitialText:@"initial text "];


    [self presentViewController:tweet animated:YES completion:^
     {

     }];
}

但是显示屏幕需要 5 到 8 秒!对我来说太长了,我看到了立即运行的应用程序.这不是我的应用程序的问题,因为我已经创建了一个仅具有此功能的新项目,并且它需要相同的功能.

But it takes between 5 and 8 seconds to show the screen! For me it's too long, I saw apps that goes instantly. It is not an issue with my app, because I have created a new project with only this functionality, and it takes the same.

所以我认为延迟是在屏幕被实例化的那一刻,所以我决定在我的标题上声明我的推文屏幕并将这部分移动到 viewDidAppear:

So I thought that the delay was in the moment that the screen is instantiated, so I have decided to declare my tweet screen on my header and moved this part to the viewDidAppear:

if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{

tweet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];

[tweet setInitialText:@"initial text "];

按钮上的方法是这样的:

and on the button method is like that:

if(tweet)
[self presentViewController:tweet animated:YES completion:^
 {

 }];

但它并没有变得更快.我正在使用 iPhone 4 并且我有一些应用程序可以非常快速地创建 Twitter 撰写屏幕,有人知道怎么做吗?

but it didn't get faster. I am using an iPhone 4 and I have some apps that creates the twitter compose screen really fast, does anybody know how to do that?

推荐答案

这个问题也困扰了我一整天!最后我得到了一些技巧来让 SLComposeViewController 看起来更快.似乎当我第一次想加载 SLComposeVC 时,SLComposer 会在主线程中占用大量资源,但之后,它会立即显示完全正常......所以我想也许我们需要加载 SLCompose在我们的视图控制器中查看(只需加载视图)和中提琴……SLComposerView 将直接呈现到视图中……

This issue has been bugging me as well for a whole day! Finally i get some trick to make the SLComposeViewController appear faster. Its seems when I want to load the SLComposeVC for the first time, The SLComposer will take a lot of resource in main thread, but after that, its will appear perfectly normal without delay... so I guess maybe we need to load the SLCompose View in our view controller (just load the view) and viola.. the SLComposerView will be directly presented into the view...

只需在您的 appdelegate 中添加此代码

Just add this code in your appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  ....

//loading the view...make twitter share dialog appear with no dellay
    if(NSClassFromString(@"SLComposeViewController") != nil){
        SLComposeViewController *composeViewController = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
        [composeViewController view];
    }
   ...
}

  • 对不起,如果我的英语不完美,我不是本地人.
  • 这篇关于如何使用 SLComposeViewController 更快地制作presentViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆