gpt4 book ai didi

ios - 嵌套参数化闭包参数异常

转载 作者:搜寻专家 更新时间:2023-11-01 05:59:29 26 4
gpt4 key购买 nike

我正在尝试使用 UIView.animateWithDuration 执行一组嵌套动画,但是无论我使用的闭包返回参数如何,我似乎都会遇到异常。

Cannot invoke 'animateWithDuration' with an argument list of type '(NSTimeInterval, delay: NSTimeInterval, options: UIViewAnimationOptions, animations: () -> Void, completion: (Bool) -> Void)'

这是有问题的函数

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

有什么建议可以尝试吗?

最佳答案

添加显式 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
})

关于ios - 嵌套参数化闭包参数异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25467931/

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