Home  >  Q&A  >  body text

objective-c - ios页面跳转有点卡顿

其中一个ViewController执行以下语句

UIViewController *vc = [[UIViewController alloc] init];
[self.navigationController pushViewController:vc animated:false];

将要被push的ViewController的viewDidLoad方法中,我init了一个textview和一个button,并且addSubview了,然后我在viewWillAppear方法中设置了他们的一点属性,用Masonry做了布局。
然后在第一次push的时候会产生卡顿,请问有什么方法避免?

PHP中文网PHP中文网2741 days ago719

reply all(12)I'll reply

  • 怪我咯

    怪我咯2017-04-18 09:17:45

    First of all, you need to clear where the lag occurs. Use Time Profiler to see it
    or you can post the code

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-18 09:17:45

    Have you set the background color in the controller you jump to?

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:17:45

    There are too many things that need to be loaded. Pay attention to your code logic. There are too many reasons for lags. You need to find out the problems and make targeted optimizations

    reply
    0
  • PHPz

    PHPz2017-04-18 09:17:45

    You can set a white background for the jumped controller view

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:17:45

    The view backgroundcolor of the skipped viewcontroller cannot be clearcolor

    reply
    0
  • 阿神

    阿神2017-04-18 09:17:45

    How to initialize an instance of a class? Isn't the name of the class you want to jump to called UIViewController.h?

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:17:45

    It may be a problem with the background color of the next page. We have encountered it before. Is it possible to set the transparency?

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:17:45

    Writing something like this, will it get stuck? It may be a backgroundColor problem, it’s best to fill in the code and take a look

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:17:45

    It is best to set the background color of the push controller, otherwise it will cause rendering lag

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 09:17:45

    Do it in view did appear. Both viewwillappear and transition animation are in the same runloop iteration, and autolayout itself is very performance-intensive. Putting both layout and animation in the same runloop iteration will increase the burden on that iteration.

    reply
    0
  • Cancelreply