Slow performance for presentViewController - depends on complexity of presentING controller?

前端 未结 5 1573
有刺的猬
有刺的猬 2021-02-04 02:30

I am presenting a view controller:

SCAAboutController2 *controller = [[SCAAboutController2 alloc] initWithNibName:nil bundle:nil];
UINavigationController *navCon         


        
相关标签:
5条回答
  • 2021-02-04 02:37

    I know I posting the answer year late. But if it is helpful for anybody else.

    Try putting (swift code)

    self.view.layer.shouldRasterize = true;
    self.view.layer.rasterizationScale = UIScreen.mainScreen().scale;
    

    for the view controller that being presented (and if it doesn't work there try putting it on the parent as well. I have put it on the both, it just helps smoothen all the other animations as well)

    Hope this helps.

    0 讨论(0)
  • 2021-02-04 02:52

    Adding the line:

    CFRunLoopWakeUp(CFRunLoopGetCurrent());

    After:

    [self presentViewController:navController animated:YES completion:nil];

    Fixed the issue for me.

    Answer taken from this thread. Found thanks to the comment by Eugene H.

    0 讨论(0)
  • 2021-02-04 02:55

    Your app is unresponsive because of several add and remove operation on a set. If you do any heavy processing on main thread the app gets block and becomes unresponsive.

    Short ans is you have a loop which is adding objects in a set and its doing that on the main thread which is making your app slow.

    If you look at your instruments the view loading buttons and rendering is pretty fast. initWithFrame , viewDidLoad is taking less than 4% of overall of time. The majority of the time is taken by NSISVairable release and retain which is done around 500 times. So you are doing something with your collection object and probably its in a loop. retain and release takes time and should not be done on main thread.

    Simple solution is :

    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
      // do all the heavy lifting here in background thread. 
    }
    

    Why does the following code does not improve anything :

    dispatch_async(dispatch_get_main_queue(), ^{
            SCAAboutController2 *controller = [[SCAAboutController2 alloc] initWithNibName:nil bundle:nil];
            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
            [self presentViewController:navController animated:YES completion:nil];
        });
    

    because you are already doing this stuff in main thread and you need to call main_queue on in background thread. You should not do any UI stuff on background thread.

    0 讨论(0)
  • 2021-02-04 02:56

    I had similar problem where the callback was on a different thread than the main thread. Using

                DispatchQueue.main.async {
                     Your_UI_update_function()
                }
    

    solves the slow UI update problem for me.

    0 讨论(0)
  • 2021-02-04 03:02

    Not sure this was the original author's problem but here is something that solved a similar problem for me: I was trying to present a view from didSelectRowAtIndexPath and I had to call deselectRowAtIndexPath before. If this may help someone...

    0 讨论(0)
提交回复
热议问题