gpt4 book ai didi

ios - 动画按钮 360 顺时针和反向返回

转载 作者:搜寻专家 更新时间:2023-11-01 05:53:38 26 4
gpt4 key购买 nike

使按钮顺时针旋转 360 度,然后逆时针旋转 360 度。但不是动画...动画始终是顺时针方向的 360 度。

func animateShowingOfMenu(){

let angle = CGFloat(180 * M_PI / 180)
UIView.animateWithDuration(0.4
, animations: { () -> Void in

self.blurView.hidden=false
self.menuBtn.transform = CGAffineTransformMakeRotation(angle)
self.menuBtn.transform = CGAffineTransformMakeRotation(0)


}) { (completion) -> Void in

print("compeleted")
}

}

func animateHidingOfMenu(){

let angle = CGFloat(-180 * M_PI / 180)
UIView.animateWithDuration(0.4
, animations: { () -> Void in

self.blurView.hidden = true
self.menuBtn.transform = CGAffineTransformMakeRotation(angle)
self.menuBtn.transform = CGAffineTransformMakeRotation(0)


}) { (completion) -> Void in

}
}

最佳答案

Swift 5 上的简单通用解决方案

你可以旋转任何东西

    //Clock-wise
rotateAnyView(view: makeOrderButton, fromValue: 0, toValue: 2.0 * Double.pi, duration: 1)

//Reverse
rotateAnyView(view: makeOrderButton, fromValue: 2.0 * Double.pi, toValue:0, duration: 1)


}

func rotateAnyView(view: UIView, fromValue: Double, toValue: Double, duration: Double = 1) {
let animation = CABasicAnimation(keyPath: "transform.rotation")
animation.duration = duration
animation.fromValue = fromValue
animation.toValue = toValue
view.layer.add(animation, forKey: nil)
}

关于ios - 动画按钮 360 顺时针和反向返回,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36193585/

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