Xcode 6 beta 7 UIView.animateWithDuration调用中的额外参数'usingSpringWithDamping'

时间:2014-09-05 03:56:49

标签: swift animatewithduration xcode6-beta7

我只是在使用Swift时才会收到此错误,我想知道其他人是否有此问题

Extra argument 'usingSpringWithDamping' in call

UIView.animateWithDuration(NSTimeInterval(doctorPracticeDuration), delay: 0.0, usingSpringWithDamping: 0.3, initialSpringVelocity: textAnimationVelocity, options: .CurveEaseInOut, animations: {}, completion: {success in })

我正在使用Xcode 6 beta 7

这很有意思:

UIView.animateWithDuration(NSTimeInterval(doctorPracticeDuration), delay: 0.0, options: .Repeat, animations: {}, completion: {finished in })

Swift中是否可能不支持使用弹簧动画?我知道它还在早期......

5 个答案:

答案 0 :(得分:3)

我花了很多时间来解决这个问题。 Swift有很糟糕的错误消息。在我的情况下,问题与完成块有关。

我在那里有这个:

label.transform = CGAffineTransformMakeTranslation(label.frame.size*2, 0)

注意这个问题?我把CGSize乘以2.修正了它并且有效。

我的建议是检查你的动画/完成块,因为问题最有可能来自那里。

答案 1 :(得分:2)

溶液:

let doctorPracticeDuration : NSTimeInterval = 1.0
let delay :NSTimeInterval = 1.0
let damping : CGFloat = 0.3
let textAnimationVelocity : CGFloat = 0.5


UIView.animateWithDuration(doctorPracticeDuration,
     delay: 0.0, 
     usingSpringWithDamping: damping, 
     initialSpringVelocity: textAnimationVelocity, 
     options: .CurveEaseInOut, 
     animations: {}, 
     completion: {success in })

因为usingSpringWithDampinginitialSpringVelocity都是CGFloat。请参考这个

这里发生的事情是CGFloatFloatDouble的类型,具体取决于您是构建32位还是64位。这正是Objective-C的工作方式,但在Swift中存在问题,因为Swift不允许隐式转换。

  

我们已经意识到这个问题,并认为这是严重的:我们现在正在评估几种不同的解决方案,并将推出一个   在后来的测试中。正如您所注意到的,您今天可以应对此问题   铸造成Double。这是不优雅但有效的: - )

     

-Chris

来自https://devforums.apple.com/message/998222

答案 2 :(得分:0)

我遇到了这个问题,上面的解决方案并没有解决它。这是因为您需要确保在持续时间和延迟方面都使用NSTimeInterval。所以上面的解决方案是正确的,但要确保你为所有参数使用正确的参数类型。

答案 3 :(得分:0)

  UIView.animateWithDuration(1.0, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: nil, animations: { }, completion: {(animated:Bool) -> () in transitionContext.completeTransition(true) });

我碰到了类似的问题,上面的一行对我有用。对我来说问题是完成块缺少参数声明。通过完整集(名称,类型和括号)声明块参数,它将起作用。

答案 4 :(得分:0)

这个错误只是让我超越了边缘。为什么要浪费时间去猜测实际错误是什么,只需使用它,并将其桥接到swift:

@interface UIView (SFU)

+ (void)animate:(double)duration delay:(double)delay damping:(double)damping velocity:(double)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion;

@end

@implementation UIView (SFU)

+ (void)animate:(double)duration delay:(double)delay damping:(double)damping velocity:(double)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion
{
    [self animateWithDuration:(NSTimeInterval)duration
                        delay:(NSTimeInterval)delay
       usingSpringWithDamping:(CGFloat)damping
        initialSpringVelocity:(CGFloat)velocity
                      options:options
                   animations:animations
                   completion:completion];
}

@end

不再有错误:

UIView.animate(
    transitionDuration(transitionContext),
    delay: 0,
    damping: 1.2,
    velocity: 15,
    options: .allZeros,
    animations: {
        srcVC.view.center.x += srcVC.view.bounds.width
    }) { finished in
        transitionContext.completeTransition(finished)
}