作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在名为 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/
我在名为 animateImages 的函数内有一个动画: func animateImagesIn(step: Int){ if step == 0{ let bounds = self
我是一名优秀的程序员,十分优秀!