gpt4 book ai didi

Swift iOS 8.0 - 在函数 rollViewDidEndDecelerating() 内调用时动画不起作用

转载 作者:行者123 更新时间:2023-11-30 13:53:32 25 4
gpt4 key购买 nike

我在名为 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)
}
}

如果我在添加到 ScrollView 之前从 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))
}
}
}

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

最佳答案

您连接了委托(delegate)吗?

添加

scrollView.delegate = self

在viewDidLoad中,如果你忘记了

关于Swift iOS 8.0 - 在函数 rollViewDidEndDecelerating() 内调用时动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33951534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com