私はちょうど、のUIViewの唯一の左上と右上のためcornerRadiusを設定するために迅速な拡張を書かれている、これは実際に動作する、以下のコード:アニメーションのあるUIViewの左上と右上隅だけのcornerRadiusの設定方法は?
extension UIView {
func addCorner(roundingCorners: UIRectCorner, cornerSize: CGSize) {
let path = UIBezierPath(roundedRect: bounds, byRoundingCorners: roundingCorners, cornerRadii: cornerSize)
let cornerLayer = CAShapeLayer()
cornerLayer.frame = bounds
cornerLayer.path = path.cgPath
self.layer.mask = cornerLayer
}
}
が、私はまたのために、これはアニメーションになりたいです例:あなたのコードの問題は、それがstrokeEnd
財産あなたがいないということです
var pathAnimation: CABasicAnimation = CABasicAnimation.animationWithKeyPath("strokeEnd")
pathAnimation.duration = 1.5
pathAnimation.fromValue = NSNumber(float: 0.0)
pathAnimation.toValue = NSNumber(float: 1.0)
pathAnimation.repeatCount = 10
pathAnimation.autoreverses = true
myShapeLayer.addAnimation(pathAnimation, forKey: "strokeEnd")
それはあなたが変更する必要があるが、 '自体をPATH'' strokeEnd'ではありません。矩形のパスと丸い角のパスを交互にする必要があります。 – matt
また、iOS 11では 'cornerRadius'が直接アニメーション化可能で、レイヤーに' maskedCorners'プロパティがあることに気づいていますか?これは基本的に1ライナーです。 – matt