请问下,我现在有一个UIScrollView,还有一个ViewControll的数组,然后我把这个数组遍历用addChildViewController添加到了UIScrollView,然后设置UIScrollView的contentSize是用ViewControll数组*屏幕宽度,达到滑动切换ViewControll。但是viewWillAppear不运行。求解释
PHP中文网2017-04-17 13:57:32
What you do is equivalent to loading all the Views into the UIScrollView at once, but some are on the screen and some are beyond the screen. They are always displayed, but you can't see it. There is no Appear at all. Action, so ViewWillAppear
will not go阿神2017-04-17 13:57:32
The answer above should be correct, I’m just here to add to it.
For this processing, you can use the proxy method of UIScrollView itself, which is the method when the drag is completed - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:
To determine the current switching, then put your ViewWillAppear
method in it and execute it.
伊谢尔伦2017-04-17 13:57:32
Promise must be called~
Here is the timing of the call (for ChildController, after all, it is a complete step in the UIViewController cycle): viewWillAppear, viewDIdAppear
is executing
[self.view addSubview:childController.view];
Called after .
On the contrary, viewWillDisappear, viewDidDisappear
is executing
[childController.view removeFromSuperview];
Called after .
If you don’t believe it, you can write a simple Demo yourself and add the following operation:
cv *c = [cv new];
[self addChildViewController:c];
[self.view addSubview:c.view];
[c didMoveToParentViewController:self];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[c.view removeFromSuperview];
});
Rewrite in cvviewWillAppear: viewWilDisappear:
and put LOG for verification.
Please refer to the above for analysis of your actual situation~