How to resize a CAGradientLayer after rotation?

前端 未结 2 649
醉话见心
醉话见心 2021-02-19 03:06

I\'m adding a CAGradientLayer to a view. When the view is auto-resized (such as after a rotation) the gradient layer is not resized. Can the gradient be set to auto

2条回答
  •  执笔经年
    2021-02-19 03:40

    I resize the layer's bounds manually by overriding the setFrame: method of the view:

    -(void)setFrame:(CGRect)frame
    {
        [super setFrame:frame];
        _gradientLayer.bounds = CGRectMake(0, 0, CGRectGetWidth(frame), CGRectGetHeight(frame));
    }
    

提交回复
热议问题