【发布时间】:2018-04-30 14:56:28
【问题描述】:
我已经设法(通过 StackOverflow 的帮助)以编程方式将部分页面卷曲添加到我的 UIPageViewController。这用于向用户提示他们已完成该页面/屏幕并可以继续。
代码如下所示:
let animation = CATransition()
animation.duration = 0.3
animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionDefault)
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
animation.endProgress = 0.2
animation.type = "pageCurl"
myPageViewController.view.layer.add(animation, forKey: "MyTransition")
这就是它的样子(对质量差表示歉意 - mp4 到 gif 不太好)
我现在真正想做的是为该动画添加一些弹簧,使其看起来更好一些。但我发现从 Google 获取任何信息真的很困难(甚至不可能?)。
这是我尝试过的:
// Can't see an animation type on here, maybe keyPath is used as the type?
let x = CASpringAnimation(keyPath: "pageCurl")
// No endProgress either, just trying some random values now
x.fromValue = 0
x.toValue = 1
// No idea - found on Google - can play with the settings later
x.damping = 5
x.duration = x.settlingDuration
// These look familiar from my working animation, so i'll set these!
x.fillMode = kCAFillModeForwards
x.isRemovedOnCompletion = false
myPageViewController.view.layer.add(x, forKey: "MyNewTransition")
... 它完全没有任何作用。甚至没有崩溃。我想这是因为你不能使用pageCurl 作为keyPath,iOS 不知道如何处理它,所以它被忽略了。
这是一个视频,大致展示了我想要从中得到什么......
那么有没有人知道是否可以制作这个 pageCurl 动画,但要有一些春天?
【问题讨论】:
-
UIView 有一个 animateWithDuration 函数,支持弹簧效果。
-
我编辑了我的评论,请看一下,让我知道它是否适合您。
-
@Adela 看起来很棒。我稍后会测试它!谢谢你的帮助。我需要再获得一些积分,但一旦我再次获得 50 分,我会再添加一个赏金并给你 :)
标签: ios swift core-animation caanimation