gpt4 book ai didi

ios - 使按钮连续动画,可用 - Swift

转载 作者:行者123 更新时间:2023-11-28 06:50:46 27 4
gpt4 key购买 nike

我希望我的按钮持续动画直到用户触摸它,这是代码

func animate() {
UIView.animateWithDuration(1, animations: { () -> Void in
self.animation.transform = CGAffineTransformMakeScale(0.8,0.8)
})
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.animation.transform = CGAffineTransformMakeScale(1,1)
})
}

使用 NSTimer

timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: Selector("animate"), userInfo: nil, repeats: true)

动画效果很好,但我找不到让它可点击的方法。

最佳答案

您需要使用一种较长形式的 animateWithDuration,它采用选项参数并指定 UIViewAnimationOptionAllowUserInteraction 选项。像这样:

UIView.animateWithDuration(1, 
delay: 0,
options: .AllowUserInteraction,
animations:
{ () -> Void in
self.animation.transform = CGAffineTransformMakeScale(0.8,0.8)
}
completion: nil
);

(我的 Swift 有点生疏,但无论如何就是这个想法。)

关于ios - 使按钮连续动画,可用 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34975461/

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