【问题标题】:how to make the Circular layer larger keeping the center fixed如何使圆形层更大保持中心固定
【发布时间】:2020-08-08 15:30:55
【问题描述】:

我有一个以父视图为中心的圆形 CAShapeLayered UIView。现在,当我点击此视图时,我想将其整体半径增加 50%。因此,我将以下动画代码附加到我的图层。

private func getLargerLayerAnimation()->CABasicAnimation { 
    let animation = CABasicAnimation(keyPath: "transform.scale")
    animation.fromValue = 1
    animation.toValue = 1.5
    animation.duration = 2.0
    animation.autoreverses = true
    animation.fillMode = .forwards
    animation.isRemovedOnCompletion = true
    return animation
}

但不是从中心放大图层,而是向右下方移动。如何保持中心不变并扩大圆形层。

【问题讨论】:

    标签: ios transform cashapelayer cabasicanimation


    【解决方案1】:

    您需要设置图层的边界以匹配圆形图层的大小。

    这里是一些示例代码:

        let circleBounds = CGRect(x: 0, y: 0, width: 100, height: 100)
        let circle = CAShapeLayer()
        circle.bounds = circleBounds      // <<<<<======
        let circlePath = UIBezierPath(ovalIn: circleBounds)
        circle.path = circlePath.cgPath
        
        view.layer.addSublayer(circle)
        circle.position = CGPoint(x: 100, y: 100)
        self.view = view
        
        circle.add(getLargerLayerAnimation(), forKey: "dummy")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-01
      • 2015-11-28
      • 2010-10-28
      • 2018-02-05
      • 2017-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多