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

swift - 立即 UIButton 旋转变换,带动画比例

In lại Tác giả: Walker 123 更新时间:2023-11-28 13:36:07 30 4
mua khóa gpt4 Nike

我想为 UIButton 的缩放设置动画,并在完成后再次为缩放设置动画,但让它在没有动画的情况下旋转。我尝试将旋转变换放在没有持续时间的动画调用中,但不知何故它仍然成为缩放动画的一部分或替换缩放动画。

我将比例的动画延长了一秒,以更清楚地展示结果。

let transforms: CGAffineTransform = .identity

button.transform = transforms

UIView.animate(withDuration: 1.05, delay: 0.0, options: .allowUserInteraction, animations: {
button.transform = transforms.scaledBy(x: 0.75, y: 0.75)
}, completion: { _ in

button.transform = CGAffineTransform(rotationAngle: 90 * (.pi/180)) // I want this to happen immediately, without animation

UIView.animate(withDuration: 1.1, delay: 0.0, options: .allowUserInteraction, animations: {
button.transform = transforms.scaledBy(x: 1.0, y: 1.0)
}, completion:nil)

})

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

您将旋转 biến đổi 设置为立即发生 - 它确实发生了!但是随后您立即开始再次为其设置动画,关于您的 transforms 变量 - 将其当前的 biến đổi 恢复为该变量中的那个。

与其使用变量来跟踪按钮的biến đổi,不如引用其当前的biến đổi, như hình dưới đây:

button.transform = .identity
UIView.animate(withDuration: 1.05, delay: 0.0, options: .allowUserInteraction, animations: {
button.transform = button.transform.scaledBy(x: 0.75, y: 0.75)
}, completion: { _ in
button.transform = CGAffineTransform(rotationAngle: 90 * (.pi/180)) // I want this to happen immediately, without animation
UIView.animate(withDuration: 1.1, delay: 0.0, options: .allowUserInteraction, animations: {
button.transform = button.transform.scaledBy(x: 1.0, y: 1.0)
}, completion:nil)

})

关于swift - 立即 UIButton 旋转变换,带动画比例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56605426/

30 4 0
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