xcode 快速按钮旋转动画以制作类似的动画

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31843485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:37:46  来源:igfitidea点击:

Button Rotation Animation in swift to make a similar Animation

iosxcodeswiftanimationrotation

提问by Omar Shiltawi

Rotate a button to make a similar animation when clicked?

单击时旋转按钮以制作类似的动画?

image
(source: cloudfront.net)

图片
(来源:cloudfront.net

回答by Caleb

Swift 3:

斯威夫特3

UIView.animate(withDuration: 0.25, animations: {
    myButton.transform = CGAffineTransform(rotationAngle: CGFloat.pi)
})

More information on rotation in Swift: Swift: How can you rotate text for UIButton and UILabel?

有关 Swift 中旋转的更多信息: Swift:如何为 UIButton 和 UILabel 旋转文本?

回答by dorian

You can use a regular rotation on the button:

您可以在按钮上使用常规旋转:

[myButton setTransform:CGAffineTransformMakeRotation(M_PI_4)];

that would rotat + a 45degrees and make it an X :)

那将旋转+ 45度并使其成为X :)

if you want to animate as well try

如果您也想制作动画,请尝试

[UIView animateWithDuration:.5 animations:^{
        myButton.transform = CGAffineTransformMakeRotation(M_PI_4);
    }];