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

查看:133
本文介绍了如何使用更快的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天全站免登陆