在 Swift 中调整带有动画的 CALayer 的大小
Resize a CALayer with animation in Swift
我已将 CALayer 添加到图像,执行以下操作:
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)
我想为图层设置动画,使其从左到右显示图像。我试过这个:
let width = CGFloat(0)
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
self.menulayer.bounds = CGRectMake(0, 0, width , 50)
CATransaction.commit()
但是动画是从图像的中心开始的,我怎样才能让它从图像的左边缘开始?
因此,为图层的原点设置动画以将其向右移动,直到您的图像视图完全显示出来。您需要设置 menuImage.layer.masksToBounds = true
以便覆盖层在滚动到图像视图的框架之外时不可见。
我已将 CALayer 添加到图像,执行以下操作:
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)
我想为图层设置动画,使其从左到右显示图像。我试过这个:
let width = CGFloat(0)
CATransaction.begin()
CATransaction.setAnimationDuration(2.0)
self.menulayer.bounds = CGRectMake(0, 0, width , 50)
CATransaction.commit()
但是动画是从图像的中心开始的,我怎样才能让它从图像的左边缘开始?
因此,为图层的原点设置动画以将其向右移动,直到您的图像视图完全显示出来。您需要设置 menuImage.layer.masksToBounds = true
以便覆盖层在滚动到图像视图的框架之外时不可见。