仅对屏幕上的视图进行动画处理

发布于 2024-12-07 11:13:06 字数 208 浏览 0 评论 0原文

所以我想在我的应用程序视图之间进行由特殊动画组成的转换。简而言之,所述动画会依次淡出您所在页面的每个子视图,然后再继续下一个。明显的问题是,如果我在某个时候使用 UIScrollView,我的动画只会淡出整个滚动视图的内容,这将花费太长时间,而不仅仅是您在屏幕上看到的内容。这让我想到了我的问题:

是否有可能获取当前在屏幕上可见的 UIView 的所有子视图?

提前致谢

So I want to have transition between my app's views that consist of 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

惜醉颜 2024-12-14 11:13:06

您可以检查哪些视图位于滚动视图的可见区域上,如下所示:

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];
}

结果是您将拥有一个数组(visibleViews),其中所有视图的矩形与滚动视图的可见矩形相交。然后,您可以仅对所述数组中的视图进行动画处理。

附言。我没有测试该代码,但它应该可以让您了解总体思路。

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.

苏璃陌 2024-12-14 11:13:06

循环遍历动画中的所有子视图并将它们从超级视图中删除,并在 commitAnimations 之前,然后更改 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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文