ios - viewWillAppear不运行。
怪我咯
怪我咯 2017-04-17 13:55:32
0
3
691

请问下,我现在有一个UIScrollView,还有一个ViewControll的数组,然后我把这个数组遍历用addChildViewController添加到了UIScrollView,然后设置UIScrollView的contentSize是用ViewControll数组*屏幕宽度,达到滑动切换ViewControll。但是viewWillAppear不运行。求解释

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
Ty80

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
阿神

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.

伊谢尔伦

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~

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!