UIViewPropertyAnimatorとCornerRadius


CornerRadiusを設定してClipToBounds した UIView を UIViewPropertyAnimatorでアニメーションさせると、boundsの形が歪んでしまう。設定したCornerRadiusのままアニメーションさせるには、アニメーターの中でCornerRadiusも設定する。

UIViewPropertyAnimator.runningPropertyAnimator(withDuration: 1, delay: 0, options: [.curveEaseInOut]) {
   animationView.frame = CGRect(x:100,y:100,width:100,height:100)
   animationView.layer.cornerRadius = animationView.frame.height/2
        } completion: { (UIViewAnimatingPosition) in

        }

これでまんまるが歪まずにアニメーションしてくれる。

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
[email protected]

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
Medium