开发者

Animate only views that are on-screen

So I want to have transition between my app's views that consist o开发者_高级运维f a special animation. In a nutshell, said animation fades out every single subview of the page you are on, one after another, before continuing to the next. The obvious problem is, if I use an UIScrollView at some point, my animation would just fade out the contents of the entire scrollview, which would take way too long, and not just the ones you see on-screen. Which brings me to my question:

Is it possible to get all the subviews of an UIView that are currently visible on-screen?

Thanks in advance


You could check which views are on the visible area of the scroll view with something like this:

CGRect visibleArea = CGRectMake(scrollView.contentOffset.x, scrollView.contentOffset.y, scrollView.view.frame.size.width, scrollView.view.frame.size.height);
NSMutableArray *visibleViews = [[NSMutableArray alloc] init];
for(UIView *view in scrollView.subviews){
  if(CGRectIntersectsRect(visibleArea, view.frame)
    [visibleViews addObject:view];
}

The result would be that you'd have an array (visibleViews) with all the views which's rects intersect with the visible rect of the scroll view. You could then animate only the views in said array.

PS. I didn't test that code, but it should give you the general idea.


Loop through all of the subviews in an animation and remove them from the superview, and before commitAnimations, and then change VC:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0f];
for (UIView *view in self.view.subviews) {
    [view removeFromSuperview];
}
[UIView commitAnimations];
[self.navigationController performSelector:@selector(pushViewController:) withObject:viewControllerToSwitchTo afterDelay:1.0f];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜