0

我在一个名为的函数中有一个动画animateImages

func animateImagesIn(step: Int){
  if step == 0{
    let bounds = self.guideView.stepOne.bounds
    UIView.animateWithDuration(1.0, delay: 0.2, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
            self.guideView.stepOne.bounds = CGRect(x: bounds.origin.x - 20, y: bounds.origin.y, width: bounds.size.width + 60, height: bounds.size.height)
            }, completion: nil)
  }

  if step == 1{
    let boundsOne = self.guideView.stepTwoLeft.bounds
    let boundsTwo = self.guideView.stepTwoRight.bounds
    UIView.animateWithDuration(1.0, delay: 0.2, usingSpringWithDamping: 0.2, initialSpringVelocity: 10, options: nil, animations: {
      self.guideView.stepTwoLeft.bounds = CGRect(x: boundsOne.origin.x + 20 , y: boundsOne.origin.y, width: boundsOne.size.width + 60, height: boundsOne.size.height)
      self.guideView.stepTwoRight.bounds = CGRect(x: boundsTwo.origin.x + 20 , y: boundsTwo.origin.y, width: boundsTwo.size.width + 60, height: boundsTwo.size.height)
    }, completion: nil)
  }
}

viewDidAppear如果我在添加到滚动视图之前从 调用该函数,它可以工作:

for index in 0...currentDictionary.count-1{     
  println("dictionary index \(index)")

  guideView = GuideView()
  var guide = currentDictionary["\(index)"]

  guideView.frame = CGRectMake(xLoc, heightOffset, width, height-heightOffset)
  guideView.title.text = guide?.title.text
  guideView.subtitle.text = guide?.description.text

  if index == 0{
    guideView.stepOne.image = UIImage(named: "step1")
    guideView.stepOne.contentMode = .ScaleAspectFit
    animateImagesIn(index)
  }

  if index == 1{
    guideView.stepTwoLeft.image = UIImage(named: "giving hand")
    guideView.stepTwoRight.image = UIImage(named: "receiving hand")
    animateImagesIn(index)
  }

  scrollView.addSubview(guideView)
  xLoc = xLoc + (width)
}

但如果我在里面调用它scrollViewDidEndDecelerating(),它不会:

func scrollViewDidEndDecelerating(scrollView: UIScrollView) {
  var currentIndex = scrollView.contentOffset.x/UIScreen.mainScreen().bounds.width

  for subIndex in 0...currentDictionary.count-1{
    if (Int(currentIndex) == subIndex){
      createCarousel(Int(currentIndex))
      animateImagesIn(Int(currentIndex))
    }
  }
}

请告诉我我哪里弄错了?谢谢!

4

1 回答 1

0

你连接代理了吗??

添加

scrollView.delegate = self

在 viewDidLoad 中,如果你忘记了

于 2015-11-28T12:45:54.247 回答