UIImageViewを上、下、左、右に移動しようとしています。アニメーションは4回4回する必要があります。中央の画像が上に移動し、次に左の位置と右の位置に移動します。 UIAnimation swift 3を使用してこれをどのように達成できますか?Swift3のUIViewアニメーション
アニメーションを使用して画像を上、左、右、下に移動するにはどうすればよいですか?それはあなたがアニメーションのための順序を指定することができますよう
UIImageViewを上、下、左、右に移動しようとしています。アニメーションは4回4回する必要があります。中央の画像が上に移動し、次に左の位置と右の位置に移動します。 UIAnimation swift 3を使用してこれをどのように達成できますか?Swift3のUIViewアニメーション
アニメーションを使用して画像を上、左、右、下に移動するにはどうすればよいですか?それはあなたがアニメーションのための順序を指定することができますよう
UIView.animate(withDuration: 1, delay:0, animations: {
//top
self.tempVW.frame.origin.y = self.tempVW.frame.origin.y - 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: {
//left
self.tempVW.frame.origin.x = self.tempVW.frame.origin.x - 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: {
//bottom
self.tempVW.frame.origin.y = self.tempVW.frame.origin.y + 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: { //right
self.tempVW.frame.origin.x = self.tempVW.frame.origin.x + 100
}, completion: {completion in
})
})
})
})
UIView.animate(withDuration: 1, delay:0, animations: {
//top
self.imageView.frame.origin.y = self.imageView.frame.origin.y - 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: {
//bottom
self.imageView.frame.origin.y = self.imageView.frame.origin.y + 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: {
//left
self.imageView.frame.origin.x = self.imageView.frame.origin.x - 100
}, completion: {completion in
UIView.animate(withDuration: 1, delay:0, animations: {
}, completion: {completion in
//right
self.imageView.frame.origin.x = self.imageView.frame.origin.x + 100
})
})
})
})
あなたは、このためにキーフレームアニメーションを使用する必要があります。以下は基本的な例です:
let animationDuration = 2.0
let position: CGFloat = 50.0
let viewToAnimate = UIImageView()
UIView.animateKeyframes(withDuration: animationDuration, delay: 0.0, options: .calculationModeLinear, animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/3, animations: {
viewToAnimate.frame.origin.y = viewToAnimate.frame.origin.y + position
})
UIView.addKeyframe(withRelativeStartTime: 1/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.y = viewToAnimate.frame.origin.y - (position * 2)
})
UIView.addKeyframe(withRelativeStartTime: 2/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.x = viewToAnimate.frame.origin.x - position
})
UIView.addKeyframe(withRelativeStartTime: 3/4, relativeDuration: 1/4, animations: {
viewToAnimate.frame.origin.x = viewToAnimate.frame.origin.x + (position * 2)
})
}, completion: { completed in
})
UIImageViewの中心をあなたの好みの場所にアニメーション表示することができます – Mannopson