0

There is a delay between viewwillappear and viewdidappear when a view controller pushed to a navigation controller. Viewwillappear will be called immediatally, while viewdidappear will be called after the transation animation finished.

I want to make a custom navigation. Viewcontroller A is a container viewcontroller. It will contain viewcontroller B or viewcontroller C. At first, viewcontroller contains viewcontroller B(A is B's parent controller). Then controller B will navigate to controller C with a transation.

But viewdidappear will be called immediatally after viewwillappear, when addsubview is called. How to add delay between viewwillappear and viewdidappear? I hope viewwillappear will be called before the animation, and viewdidappear will be called after the animation. Can you help me?

Zhang Jiuzhou
  • 663
  • 7
  • 19
  • There is a button in viewcontroller B's view. When tap the button, it will navigate to controller C. It looks like pushviewcontroller. The diffrence is, viewcontroller B will be dealloced. – Zhang Jiuzhou Jul 06 '15 at 07:42
  • I do not want to use navigationcontroller and pushviewcontrller, because there is a lot of viewcontrollers(viewcontroller D, viewcontroller E...), I do not want leave them in the memory when they are not shown. – Zhang Jiuzhou Jul 06 '15 at 07:44

2 Answers2

0

There is a good way to manually delay, try to put this in the bottom of viewwillappear

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
  NSLog(@"Do some work");
});

Hope this could help.

Nghia Luong
  • 794
  • 1
  • 5
  • 11
0

How about this way?

  1. There is only one container - view controller A.
  2. B, C, D... are all subviews instead of view controllers.
  3. First, view controller A has view B by default.
  4. And then click button in view B.
  5. Do the animation for C and then in the completion block hide B or delete B.

Hopes this is helpful.

brianLikeApple
  • 3,803
  • 1
  • 23
  • 44