我在UIImageView上添加了CAGradientLayer。我已经在UIImageView上设置了自动调整大小的蒙版,使其在所有边界上都是灵活的(灵活的高度,宽度等)。但是,当UIImageView调整大小时,我在imageView顶部添加的渐变层不会调整大小。为什么是这样?这是代码:
CAGradientLayer *imgOverlay = [CAGradientLayer layer];
CGColorRef startBlueColor = [UIColor colorWithRed:23/255.f green:171/255.f
blue:219/255.f alpha:0.8].CGColor;
CGColorRef endBlueColor = [UIColor colorWithRed:23/255.f green:171/255.f
blue:219/255.f alpha:0.5].CGColor;
imgOverlay.colors = [NSArray arrayWithObjects:
(id) startBlueColor,
(id) endBlueColor,
nil];
imgOverlay.locations = [NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:1.0],
nil];
imgOverlay.startPoint = startPoint;
imgOverlay.frame = self.backgroundImageView_.bounds;
imgOverlay.endPoint = endPoint;
self.imageOverlay = imgOverlay;
[self.backgroundImageView_.layer addSublayer:self.imageOverlay];
最佳答案
CALayer不支持在iOS上自动调整大小。您必须在layoutSubviews或适当的地方手动实现调整大小。