【发布时间】:2016-01-02 01:19:06
【问题描述】:
我想将另一个图像(水平和垂直)对齐以创建动画。动画很简单:心脏会在 Angry Bedou 的标志内“振动”,但他必须在该图像中“居中”。
我正在尝试以下方法:
func animate() {
heartImg.frame = CGRectMake(angryBedousImg.frame.size.width / 2, angryBedousImg.frame.size.height / 2, heartImg.frame.size.width, heartImg.frame.size.height)
let heartAnimation = CABasicAnimation(keyPath: "position")
heartAnimation.duration = 0.09
heartAnimation.repeatCount = .infinity
heartAnimation.autoreverses = true
heartAnimation.fromValue = NSValue(CGPoint: CGPointMake(heartImg.center.x - 1, heartImg.center.y))
heartAnimation.toValue = NSValue(CGPoint: CGPointMake(heartImg.center.x + 1, heartImg.center.y))
heartImg.layer.addAnimation(heartAnimation, forKey: "position")
}
但是当我构建应用程序时它不会集中。动画有效,但对齐无效。我希望在纵向模式下在每个设备中进行对齐工作。
我看了故事板,图像很好。我做错了什么?
【问题讨论】:
-
通过情节提要?我做到了。
-
我不知道该怎么做=/
-
很抱歉@LeoDabus,但我不明白您给出的解决方案
-
我知道如何制作动画。我不知道该怎么做,就是把心放在图像“愤怒的贝都”的中心,每个设备的作品。事实上,它在任何设备测试中都不起作用。
-
首先分解你的问题,如何将它定位在其他图像中心
标签: ios swift cabasicanimation