2016-11-23 1 views
1

나는 다른 속도로 배경에서 애니메이션으로 스크롤해야하는 이미지 펀치 (5-6 이미지)가 있습니다. UIScrollView가 아닌 ​​UIView에 배치했습니다. 나는 사용자가 볼 스크린 뒤 이미지를 복사하는 것이 화면에 이미지를 추가 Method screen배경 이미지 애니메이션 스크롤

:

는 지금은 그것을 위해이 방법을 가지고있다. 하지만 그 이미지와 copyImages (화면 뒤)가 동일한 거리를 통과해야하기 때문에 다른 속도를 가지고 있습니다 (내가 넣은 것은 아닙니다). 그래서 제대로 작동하지 않습니다.

아무도 도와 줄 수 있습니까?

P. 일부 이미지는 크기가 다르기 때문에 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) 
    } 

} 
+0

내부에 수평 스택 뷰 또는 콜렉션 뷰가있는 스크롤 뷰에 배치하는 것이 더 쉬울 수도 있습니다. 그런 다음 스크롤 뷰의 내용 오프셋에 속도 및 속도로 애니메이션을 적용하면됩니다. 필요한 반복 횟수? 또한 코드를 질문에 복사하는 것이 가장 좋습니다. 응답하기가 더 쉬워집니다. –

+0

@twiz_ 시도했지만 스크롤보기가 제대로 작동하지 않고 다른 이미지에 다른 스크롤 속도를 추가 할 수 없습니다. –

답변

0

UICollectionView은 이미지의 단순한 표시 및 애니메이션에 사용할 수 있습니다. 애니메이션의 경우, 필요한 시간 간격 후에 scrollToItemAtIndexPath:atScrollPosition:animated: 메서드를 사용해야합니다.

+0

흠 ... 확실하지 않지만 컬렉션보기로 스크롤하는 이미지를 반복하는 방법을 상상할 수 없습니다 ... –

+0

끝없는 스크롤을 원하십니까? –

+0

예. 게임에서 보여주는대로 알 수 있습니다. 무한대 배경 스크롤링. 하지만 위젯 내부에서하고 있기 때문에 나에게 몇 가지 제한이 있습니다. –