我在UIImageView上添加了一个CAGradientLayer。我已经在UIImageView上设置了自动调整遮罩,使其在所有边界都是灵活的(灵活的高度,宽度等等)。但是,我在imageView上添加的渐变层在UIImageView调整大小时不会调整大小。为什么是这样?这是代码:
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];
答案 0 :(得分:8)
CALayer不支持在iOS上自动调整大小。您必须在layoutSubviews中或在适当的位置手动实现调整大小。