Resize CALayer with animation in Swift

I added CALayer to the image by doing the following:

var menulayer = CALayer()
menulayer.frame = CGRectMake(0.0, 0.0, menuimage.frame.size.width, menuimage.frame.size.height);
            menulayer.backgroundColor = bartint.CGColor
            menulayer.opacity = 1
            menuimage.layer.addSublayer(menulayer)

I want to animate a layer so that it displays an image from left to right. I tried this:

            let width = CGFloat(0)

            CATransaction.begin()
            CATransaction.setAnimationDuration(2.0)
            self.menulayer.bounds = CGRectMake(0, 0, width , 50)
            CATransaction.commit()

But the animation starts in the center of the image, how can I start it from the left edge of the image?

+4
source share
1 answer

Animate the origin of the layer to move it to the right until the image is fully open. You will need to set menuImage.layer.masksToBounds = trueso that the coating layer is not visible when it scrolls from the image frame.

+1
source

Source: https://habr.com/ru/post/1599669/


All Articles