我希望我的按钮持续动画直到用户触摸它,这是代码
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/