- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 CAKeyframeAnimation,它在风景中看起来很棒,但是当设备旋转时,与其余内容相比,动画当然不合适。有没有办法调整(缩放)正在进行的动画的路径?
编辑:添加代码
let circle = CAShapeLayer()
circle.path = UIBezierPath(roundedRect: CGRect(x: -60.0, y: -60.0, width: 100.0, height: 100.0), cornerRadius: 50.0).cgPath
circle.fillColor = UIColor.clear.cgColor
circle.strokeColor = UIColor.blue.cgColor
let animation = CAKeyframeAnimation(keyPath: "position")
animation.duration = (path["endTime"] as! Double) - (path["startTime"] as! Double)
animation.repeatCount = 0
animation.path = (path as! UIBezierPath).cgPath
animation.calculationMode = kCAAnimationPaced
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
circle.add(animation, forKey: "position")
self.view.layer.insertSublayer(circle, at: 5)
问题是 UIBezierPath 是在纵向或横向(应用程序支持两者)中定义的,因此以与创建时相同的方向播放是没有问题的,但是如果您旋转设备,则 UIBezierPath 定义的动画应该是针对新方向进行了更新。我只是在寻找一种在设置动画时将 CAKeyframeAnimation 路径更新到新坐标系的方法。
最佳答案
我发现您无法即时调整路径,但您可以根据原始路径中的点和计算出的比例/平移创建新路径。
要从 UIBezierPath 获取 CGPoints 数组,您可以使用此方法:https://stackoverflow.com/a/36374209/1491675
对于动画开始后的设备旋转,保留对动画中当前点的引用,并在设备旋转时重新计算路径,并用新动画替换现有动画,删除已经发生的动画部分。
关于swift - CoreAnimation 和设备旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41794961/
就在appdelegates中,applicationDidBecomeActive。我创建并启动一个线程,这个线程等待异步下载然后保存数据: - (void)applicationDidBecom
我有一个非常简单的 CA 演示。它使用图像文件中的内容创建一个图层,并显示该图像。当您在窗口中单击时,它会使用隐式动画将图像平滑地移动到鼠标点。这工作正常,运行完美流畅。但是,随着窗口变大,平滑度会变
我有一个 CALayer A 和一个子层 B我想要调整 A 的大小(缩小),所以我将动画添加到我的图层 A但是当我提交动画子层 B 时并没有缩小。它的大小保持不变(但它的位置随着其 super 层边界
我正在尝试对图层的背景颜色从红色到蓝色进行简单的 CABasicAnimation。 添加动画并设置模型层的最终值后,动画闪烁为蓝色,然后再次变为红色,并动画为蓝色。 我的代码是: override
我经常面临对 View 进行动画处理并将其恢复到其原始值的要求。 (类似于在 Tap 上放大 UIImageView 并返回) 是否有更优雅的解决方案来跟踪原始值,而不是创建类字段并在 viewDid
我目前正在这样做: NSData *response = [NSURLConnection sendSynchronousRequest:request returningRespon
我想做的是左右旋转 View ,同时上下移动它的位置。 这是我的代码: CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineT
我有一个 CAKeyframeAnimation,它在风景中看起来很棒,但是当设备旋转时,与其余内容相比,动画当然不合适。有没有办法调整(缩放)正在进行的动画的路径? 编辑:添加代码
我正在尝试从 UIView vertical flip animation 的答案中运行代码问题,我在 Xcode 中不断收到此错误: error: Semantic Issue: Assigning
我正在尝试创建一个相当简单的 CoreAnimation 以用于 AVComposition。我的目标是创建一个 CALayer,它通过各种子层淡入淡出标题,然后淡入淡出图像。基本上是幻灯片。这正在使
布局 在uiview中与位置,尺寸有关的属性有 frame bounds center在此不多赘述,在calayer中同样有与其相对应的属性 frame bounds position 需要注意的
CoreAnimation(一)CALayer CoreAnimation 算是一个大话题 ,要实现很多炫酷的动画,必须掌握它,掌握它之前 ,先来了解CALayer — 图层 CALayer 我们平常
当核心动画在其上运行时,是否可以将一个 View 保留在另一个 View 之上? 我正在从顶部和底部滑入和滑出 View 。目前,滑出的 View 滑过当前可见的所有其他 View 的顶部,我想知道是
我正在尝试绘制一个棱镜并使用 CoreAnimation 对其进行动画处理。但我找不到一个好的解决方案来绘制彩虹色的扇子。 有几种方法可以做到这一点,每种方法都有缺点: 我可以简单地使用图像。但我允许
我凭经验接近核心动画和绘图。我正在尝试为一个简单的形状设置动画;所讨论的形状由 3 条线加上一条贝塞尔曲线形成。还绘制了一条红线,以显示曲线控制点。 alt text http://img.skitc
我正在尝试执行一些全屏动画效果,例如移动/缩放窗口以及文件如何“跳转”到 Safari 中的下载文件夹的效果。 我的第一次尝试是使用 NSImageView 内容 View 创建窗口,并使用 Core
我正在创建一个自定义(层托管)文档 View ,它包含在 ScrollView 中。根层有两个大小相同的子层——一个用于 View 的内容,另一个用于需要悬停在主要内容上的任何内容。我将框架设置为 2
我正在用核心动画做一些动画,但我找不到一种方法来知道动画 block 何时完成的通知或事件,就像在 UIVIew 动画 block 中一样 setAnimationDidStopSelector: 我
我希望有一个倒计时指示器,就像一个圆圈,从一段拱形开始到一个完整的圆圈。 我试了好几种方法,最后都是拱形直接转成一个完整的圆,而不是顺时针转。演示图片如下: 有什么想法吗?非常感谢! 最佳答案 Set
出于各种原因,我使用 CADisplayLink 手动制作动画: - (void)update:(CADisplayLink *)sender; { // Linearly interpola
我是一名优秀的程序员,十分优秀!