I want to align an image in another (horizontally and vertically) to create an animation. The animation is simple: the heart will "vibrate" inside the Angry Bedou's logo, but he must be "centered" in that image.
I was trying the following:
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")
}
But it wont centralizes when i build the app. The animation works, but not the alignment. I want the alignment work in every device in portrait mode.
I look at the storyboard, and the images are fine. What i'm doing wrong?