我有一些圖像(5-6圖像),應該以不同的速度在背景上動態滾動。我把它們放在UIView上,而不是放在UIScrollView中。返回地面圖像動畫滾動
現在我有它這個方法:
我的屏幕,用戶看到和屏幕後方圖像的副本上添加圖像。但由於圖像和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_我試過了,但滾動視圖無法正常工作,並且比我無法爲不同的圖像添加不同的滾動速度 –