我有一个walkthroughdidscoll函数,然后是一个动画函数,可以帮助执行缩放,旋转和动画。这是代码。这是我得到的错误的图像。
func walkthroughDidScroll(_ position: CGFloat, offset: CGFloat) {
for(i in 0 ..< subsWeights.count ){
// Perform Transition/Scale/Rotate animations
switch animation{
case .Linear:
animationLinear(i, offset)
case .Zoom:
animationZoom(i, offset)
case .Curve:
animationCurve(i, offset)
case .InOut:
animationInOut(i, offset)
}
// Animate alpha
if(animateAlpha){
animationAlpha(i, offset)
}
}
}
答案 0 :(得分:1)
删除括号。
for i in 0 ..< subsWeights.count {
答案 1 :(得分:0)
你应该这样做:
func walkthroughDidScroll(_ position: CGFloat, offset: CGFloat) {
for i in 0 ..< subsWeights.count {
// Perform Transition/Scale/Rotate animations
switch animation{
case .Linear:
animationLinear(i, offset)
case .Zoom:
animationZoom(i, offset)
case .Curve:
animationCurve(i, offset)
case .InOut:
animationInOut(i, offset)
}
// Animate alpha
if(animateAlpha){
animationAlpha(i, offset)
}
}
}
这是这种类型的for循环的基本结构,带有一个例子:
for index in 1...5 {
print("\(index) times 5 is \(index * 5)")
}
// 1 times 5 is 5
// 2 times 5 is 10
// 3 times 5 is 15
// 4 times 5 is 20
// 5 times 5 is 25