1
私はx画像のリストを持っています。 Iは、YとUIImageViewを作成し、各像視野高さとランダムXこの時点でランダムな遅延(1つずつ)とランダムな水平位置のアニメーションスクロール画像
func computeImageFrame() -> CGRect {
let imageWidth: CGFloat = 91
let imageHeight: CGFloat = 131
var x = xPos()
let y = yPos()
if (x > ((self.backgroundView?.bounds.width)! - (self.backgroundView?.bounds.width)! * 0.20)){
x = x.truncatingRemainder(dividingBy: ((self.backgroundView?.bounds.width)! - (self.backgroundView?.bounds.width)! * 0.20))}
return CGRect(x: x, y: y, width: imageWidth, height: imageHeight)
}
func xPos() -> CGFloat {
return CGFloat(arc4random_uniform(UInt32((self.backgroundView?.frame.size.width)!)))
}
func yPos() -> CGFloat {
return self.backgroundView.bounds.height
}
ため、I xはランダムであり、yはviewHeightでありUIImageViewsのリストを持っています今私は私の質問は、私は彼らが次々と撃つのではなく、同時にするために得ることができる方法で、どのように私が今までで、各画像の水平位置を再計算することができます
func animateBackgroundFor(_ imageViews: [UIImageView]) {
for imageView in imageViews {
self.backgroundView.addSubview(imageView)
}
// Animate background
UIView.animate(withDuration: 6.0, delay: 0.0, options: [UIViewAnimationOptions.repeat, UIViewAnimationOptions.curveLinear], animations: {
for imageView in imageViews {
imageView.frame = imageView.frame.offsetBy(dx: 0.0, dy: -7 * imageView.frame.size.height)
}
}, completion: nil)
}
をアニメーション化しようとしていますyループ。
はあなたに
編集ありがとう:言及するのを忘れ、私は次の解決方法を試してみてください
func animateBackgroundFor(_ imageViews: [UIImageView]) {
for imageView in imageViews {
self.backgroundView.addSubview(imageView)
}
for imageView in imageViews {
UIView.animate(withDuration: 6.0, delay: 1.2, options: [UIViewAnimationOptions.repeat, UIViewAnimationOptions.curveLinear], animations: {
imageView.frame = imageView.frame.offsetBy(dx: 0.0, dy: -7 * imageView.frame.size.height)
}, completion: nil)
}
}
!ありがとう! –