cuốn sách gpt4 ai đã làm

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

In lại Tác giả: Walker 123 更新时间:2023-11-28 06:50:46 27 4
mua khóa gpt4 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)

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

câu trả lời hay nhất

您需要使用一种较长形式的 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
Đề xuất bài viết: C++ boost::mpl::type 前向声明
Đề xuất bài viết: swift - 使 Swift 协议(protocol)在关联类型上符合 Equatable
Đề xuất bài viết: swift - 使用随机数选择变量
Đề xuất bài viết: ios - 拦截 oauth2 回调
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress