Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 嵌套参数化闭包参数异常_Ios_Objective C_Uiview_Swift_Closures - Fatal编程技术网

Ios 嵌套参数化闭包参数异常

Ios 嵌套参数化闭包参数异常,ios,objective-c,uiview,swift,closures,Ios,Objective C,Uiview,Swift,Closures,我试图使用UIView.animateWithDuration执行一组嵌套动画,但是无论我使用的闭包返回参数是什么,我似乎都会遇到异常 无法使用类型为的参数列表调用“animateWithDuration” '(NSTimeInterval,延迟:NSTimeInterval,选项: UIViewAnimationOptions,动画:()->无效,完成:(Bool)-> “无效” 这是令人不快的功能 func animateLikeButton(button: UIButton?) {

我试图使用
UIView.animateWithDuration
执行一组嵌套动画,但是无论我使用的闭包返回参数是什么,我似乎都会遇到异常

无法使用类型为的参数列表调用“animateWithDuration” '(NSTimeInterval,延迟:NSTimeInterval,选项: UIViewAnimationOptions,动画:()->无效,完成:(Bool)-> “无效”

这是令人不快的功能

func animateLikeButton(button: UIButton?)
{
    button?.userInteractionEnabled = false;

    let pixelsToScale = 9.0;
    let pixelsToShrink = 4.0;

    let buttonFrame = button?.frame

    // Big
    let scaleOriginX = Double(buttonFrame!.minX) - pixelsToScale / 2.0
    let scaleOriginY = Double(buttonFrame!.minY) - pixelsToScale / 2.0
    let scaleSizeX = Double(buttonFrame!.width) + pixelsToScale
    let scaleSizeY = Double(buttonFrame!.height) + pixelsToScale

    // Small
    let shrinkOriginX = Double(buttonFrame!.minX) + pixelsToScale / 2.0
    let shrinkOriginY = Double(buttonFrame!.minY) + pixelsToScale / 2.0
    let shrinkSizeX = Double(buttonFrame!.width) - pixelsToScale
    let shrinkSizeY = Double(buttonFrame!.height) - pixelsToScale

    UIView.animateWithDuration(NSTimeInterval(0.4), delay:NSTimeInterval(0), options: UIViewAnimationOptions.CurveEaseInOut,
        animations:
        {
            () -> Void in
            button?.frame = CGRect(origin: CGPoint(x: scaleOriginX, y: scaleOriginY), size: CGSize(width: scaleSizeX, height: scaleSizeY))
        },
        completion:
        {
            (finished: Bool) -> Void in
            UIView.animateWithDuration(NSTimeInterval(0.2), delay:NSTimeInterval(0.1), options: UIViewAnimationOptions.CurveEaseInOut,
                animations:
                {
                    () -> Void in
                    button?.frame = CGRect(origin: CGPoint(x: shrinkOriginX, y: shrinkOriginY), size: CGSize(width: shrinkSizeX, height: shrinkSizeY))
                },
                completion:
                {
                    (finished: Bool) -> Void in
                    UIView.animateWithDuration(NSTimeInterval(0.2), delay:NSTimeInterval(0), options: UIViewAnimationOptions.CurveEaseInOut,
                        animations:
                        {
                            () -> Void in
                            button?.frame = buttonFrame!
                        },
                        completion:
                        {
                            (finished: Bool) -> Void in
                            button?.userInteractionEnabled = true
                        }
                    )
                }
            )
        }
    )
}
老实说,我必须尝试过闭包返回参数的所有可能组合(有选项和没有选项),但没有运气。例如:

(_) -> Void in
(finished: Bool) in
(finished: Bool) -> bool in
finished in
_ in

有什么建议让我试试吗?

问题似乎是并非所有命名参数都是必需的,而且大括号和圆括号会根据嵌套的不同而变化

UIView.animateWithDuration(NSTimeInterval(0.4), delay: NSTimeInterval(0.0), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
        button?.frame = CGRect(origin: CGPoint(x: scaleOriginX, y: scaleOriginY), size: CGSize(width: scaleSizeX, height: scaleSizeY))
    }) { (finished) -> Void in
        UIView.animateWithDuration(NSTimeInterval(0.2), delay: NSTimeInterval(0.1), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            button?.frame = CGRect(origin: CGPoint(x: shrinkOriginX, y: shrinkOriginY), size: CGSize(width: shrinkSizeX, height: shrinkSizeY))
        }, completion: { (finished) -> Void in
            UIView.animateWithDuration(NSTimeInterval(0.2), delay: NSTimeInterval(0.0), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                button?.frame = buttonFrame!
            }, completion: { (finished) -> Void in
                button?.userInteractionEnabled = true
            })
        })
    }

问题似乎是并非所有命名参数都是必需的,而且大括号和圆括号也会根据嵌套的不同而变化

UIView.animateWithDuration(NSTimeInterval(0.4), delay: NSTimeInterval(0.0), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
        button?.frame = CGRect(origin: CGPoint(x: scaleOriginX, y: scaleOriginY), size: CGSize(width: scaleSizeX, height: scaleSizeY))
    }) { (finished) -> Void in
        UIView.animateWithDuration(NSTimeInterval(0.2), delay: NSTimeInterval(0.1), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            button?.frame = CGRect(origin: CGPoint(x: shrinkOriginX, y: shrinkOriginY), size: CGSize(width: shrinkSizeX, height: shrinkSizeY))
        }, completion: { (finished) -> Void in
            UIView.animateWithDuration(NSTimeInterval(0.2), delay: NSTimeInterval(0.0), options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
                button?.frame = buttonFrame!
            }, completion: { (finished) -> Void in
                button?.userInteractionEnabled = true
            })
        })
    }

添加显式的
返回应该可以解决问题。下面的代码显示了一个示例:

UIView.animateWithDuration(1.0, delay: 1.0, options: nil, animations:
{
    self.imgIcon?.alpha = 0.0
    return
},
completion:
{
    finished in
    self.imgIcon?.hidden = true
    return
})

添加显式的
返回应该可以解决问题。下面的代码显示了一个示例:

UIView.animateWithDuration(1.0, delay: 1.0, options: nil, animations:
{
    self.imgIcon?.alpha = 0.0
    return
},
completion:
{
    finished in
    self.imgIcon?.hidden = true
    return
})

如果代码有效,请不要忘记接受您的答案。@tyu,当然,但还不能这样做,从最初发布问题到现在还不到两天。如果代码有效,请不要忘记接受您的答案。@tyu,当然,但还不能这样做,从最初发布问题到现在还不到两天。原因在中解释,原因在中解释