私は、バックグラウンドで異なる速度でアニメーションスクロールする必要がある画像のパンチ(5-6画像)を持っています。私はそれらをUIScrollViewではなくUIViewに置いています。私は、ユーザーが画面の後ろに表示し、画像のコピーという画面上に画像を追加する バックグラウンド画像アニメーションスクロール
:
今、私はそれのために、この方法を持っています。しかし、そのイメージと(画面の後ろにある)copyImagesが同じ距離を通過しなければならないので、それらは異なったスピードを持っています。 それは私のためにはうまくいきません。
誰でもお手伝いできますか?
P.S.いくつかの画像はサイズが異なるので、私はそれらのためにyPosを変更する必要があります。ちょうど精緻化のため。
func setUpBackGroundLayersWithArray(){
var xPos: CGFloat = 0
for (index,image) in self.backGroundsImages.reverse().enumerate(){
var yPos:CGFloat = -30
switch index {
case 1: yPos = -10
xPos = 320
case 2: yPos = -10
default: yPos = -30
}
let imageView = UIImageView(image: image)
imageView.frame = CGRectMake(xPos, yPos, image.size.width, image.size.height)
imageView.contentMode = .ScaleAspectFit
self.addSubview(imageView)
let copyimageView = UIImageView(image: image)
copyimageView.frame = CGRectMake(320, yPos, image.size.width, image.size.height)
copyimageView.contentMode = .ScaleAspectFit
self.addSubview(copyimageView)
self.layoutIfNeeded()
let animator = UIViewPropertyAnimator(duration:8 - Double(index + 1), curve: .Linear, animations: {
UIView.animateKeyframesWithDuration(0, delay: 0, options: [.Repeat], animations: {
imageView.frame = CGRectMake(0 - copyimageView.frame.size.width, imageView.frame.origin.y, imageView.frame.size.width, imageView.frame.size.height)
}, completion: nil)
})
let secondAnimator = UIViewPropertyAnimator(duration:10 - Double(index + 1), curve: .Linear, animations: {
UIView.animateKeyframesWithDuration(0, delay: 0, options: [.Repeat], animations: {
copyimageView.frame = CGRectMake(0-copyimageView.frame.size.width, copyimageView.frame.origin.y, copyimageView.frame.size.width, copyimageView.frame.size.height)
}, completion: nil)
})
self.animators.append(animator)
self.animators.append(secondAnimator)
}
}
スクロールビューの中に水平スタックビューを持つ、またはコレクションビューを作成し、スクロールビューのコンテンツオフセットをスピードあなたが必要とする繰り返し回数?また、あなたの質問にコードをコピーすることをお勧めします。答えが生きやすくなります。 –
@twiz_私はそれを試してみましたが、スクロールビューは正常に動作しません。異なる画像に対して異なるスクロール速度を追加することはできません。 –