• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 是否可以继承 CAAnimation?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 11:04:12 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我只想通过中心点 C 和半径 R 的圆弧从 A 点到 B 点对图层的 position 属性进行动画处理。如此简单,但我觉得我正在尝试弯曲 Core Animation一半来做到这一点。

似乎理想的方法是简单地创建一个自定义 CAPropertyAnimation 子类,例如:

let anim = MyArcPropertyAnimation(keyPath: "position", center: CGPoint, radius: CGFloat)
anim.fromValue = fromPoint
anim.toValue = toPoint
myLayer.addAnimation(anim, forKey: "positionArcAnimation")

但我找不到任何关于子类化 CAAnimation 或其任何派生类的信息。 bjc(cs)CAValueFunction" rel="noreferrer noopener nofollow">CAValueFunction 似乎也是如此这似乎也很有希望。

注意:我使用 POP 运行它很容易,但发现,as warned by a facebook engineer ,性能对我来说太慢了。



Best Answer-推荐答案


文档似乎暗示 CAAnimation 不是为子类化而设计的。此外,大多数动画都是在窗口服务器(称为 backboardd)中执行的,您肯定无法让 backboardd 来执行您的代码。

不管怎样,听起来你可以使用 CAKeyframeAnimation 获得你想要的效果。将 CAKeyframeAnimationpath 属性设置为您希望图层遵循的弧线。 Playground 示例:

import UIKit
import XCPlayground

let view = UIView(frame: CGRectMake(0, 0, 400, 400))
view.backgroundColor = .whiteColor()
let mover = UIView(frame: CGRectMake(0, 0, 10, 10))
mover.backgroundColor = .redColor()
view.addSubview(mover)
XCPlaygroundPage.currentPage.liveView = view

let animation = CAKeyframeAnimation(keyPath: "position")
let path = UIBezierPath(arcCenter: CGPointMake(200, 200), radius: 160, startAngle: 1, endAngle: 5, clockwise: true)
animation.path = path.CGPath
animation.duration = 2
animation.calculationMode = kCAAnimationPaced
mover.layer.addAnimation(animation, forKey: "position")
mover.center = path.currentPoint

结果:

playground demo

关于ios - 是否可以继承 CAAnimation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36855798/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap