如何在视图出现后立即启动核心动画?
我正在尝试在视图循环期间的确切时刻对图层进行动画处理。举例来说,动画是一个简单的淡入(应用于不透明度键的 CABasicAnimation)。但我不知道如何确保 CALayer 上的动画仅在我确定包含视图(和图层)可见时才开始。
2个示例案例:
仅在容器视图之后淡入图层(以及容器视图的超级图层) 该层)已经对用户可见,响应 超级视图的控制器被推送到导航控制器中 堆。也就是说,仅在动画和 viewController->view 之后 由 [navigationController PushViewController:x 触发的设置 动画:是];已经完成并且 viewController 的视图是 已经可见。
仅在用户滚动后,通过滚动条淡入图层 分页查看,到某个页面。即用户滚动到第n页 (并且每个页面都是滚动视图的子视图)并且仅在新的之后 页面已滚动到内容视图的中心,是否 动画开始。
这有点像,一旦翻过“书”页就开始动画,以便在每一页上讲述一个故事。
有道理吗?
I'm trying to animate a layer at exact moments during a view's cycle. Let's say, for instance, the animation is a simple fade in (a CABasicAnimation applied to the opacity key). But I can't figure how to make sure my animation on a CALayer only starts once I'm sure the containing view (and layer) are visible.
2 example cases:
Fade the layer in ONLY after the container view (and super layer of
this layer) are already visible to the user, in response to the
superview's controller being pushed into a navigation controllers'
stack. That is, ONLY after the animation and viewController->view
setup triggered by [navigationController pushViewController:x
animated:YES]; has completed and the viewController's view is
already visible.Fade the layer in ONLY after the user has scrolled, through a scroll
view with paging, to some page. That is, the user scrolls to page n
(and each page is a subview of a scroll view) and ONLY after the new
page has scrolled to the center of the content view, does the
animation start.
It's sort of like, starting animations once a "book" page is turned, so as to tell a story on each page.
Makes sense?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我弄清楚了两种情况:
对于第一种情况,动画代码需要在viewDidAppear:中,关键是将动画包含在CATransaction中。由于某种原因,如果没有显式事务,动画似乎不会进行。
第二个示例非常相似,只是将 CATransaction 添加到滚动视图的委托 DidEndDecelerating 方法中:
I figured out both cases:
For the first case, the animation code needs to be in viewDidAppear: and the key is to enclose the animation in a CATransaction. For some reason, without the explicit transaction the animation doesn't seem to take.
The second example is pretty similar, only that one would add the CATransaction in the scrollview's delegate DidEndDecelerating method: