我需要一个视图,在某些条件下有圆角,在其他条件下有规则的方形。
但是,当我在第一次设置视图后尝试重新设置视图的 layer.mask 时,视觉上没有任何变化。
我首先在 layoutSubviews 方法中设置角点
- (void)layoutSubviews
{
// Create the mask image by calling the function
UIImage *mask = MTDContextCreateRoundedMask( self.bounds, 10.0, 0.0, 10.0, 0.0 );
// Create a new layer that will work as a mask
CALayer *layerMask = [CALayer layer];
layerMask.frame = self.bounds;
// Put the mask image as content of the layer
layerMask.contents = (id)mask.CGImage;
// set the mask layer as mask of the view layer
self.layer.mask = layerMask;
}
然后一旦满足条件,我就会调用另一种方法
- (void)resetCorners {
// Create the mask image by calling the function
UIImage *mask = MTDContextCreateRoundedMask( self.bounds, 0.0, 0.0, 0.0, 0.0 );
// Create a new layer that will work as a mask
CALayer *layerMask = [CALayer layer];
layerMask.frame = self.bounds;
// Put the mask image as content of the layer
layerMask.contents = (id)mask.CGImage;
// set the mask layer as mask of the view layer
self.layer.mask = layerMask;
}
但是没有视觉上的变化。我需要做什么?