ios – Altering a CAShapeLayer’s bounds measurement peak would not change the precise measurement, it adjustments it is place


A CAShapeLayer is added as a sublayer of a view in a sure place:

// Use Bezier Path to create a rectangle form
let barRect = CGRect(x: 0, y: 0, width: 10, peak: 100)
let barPath = UIBezierPath(rect: barRect)
let bar = CAShapeLayer()
bar.path = barPath.cgPath
bar.lineWidth = 0.5
// Place anchor on decrease left nook of the rectangle
bar.anchorPoint = CGPoint(x: 0, y: 1)
bar.bounds = CGRect(origin:, measurement: barRect.measurement)
// Place bar in view = CGPoint(x: 0, y: 200)

In a while, an motion makes an attempt to extend the peak of the rectangle:

bar.bounds.measurement.peak = 150

When this motion is executed, the rectangle adjustments it is place within the view, however not it is peak. The highest of the rectangle strikes to the place the rectangle ought to be if the peak is elevated, however the backside of the rectangle additionally strikes up, sustaining the unique peak of the rectangle. What’s the drawback right here? Thanks