UIRectCornerTopRight的圆角不起作用

use*_*342 1 objective-c uiview ios

我正在使用以下代码尝试绕过UIView的右上角:

UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerTopRight cornerRadii:CGSizeMake(10.0, 10.0)];

CAShapeLayer* shape = [[CAShapeLayer alloc] init];
[shape setPath:rounded.CGPath];

view.layer.mask = shape;
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,UIView不会绕过右角:

但是,当我从UIRectCornerTopRight更改为UIRectCornerTopLeft时,它似乎工作:

bey*_*ulf 5

我假设你在viewDidLoad中有这个代码,或者在布局引擎调整了你的文本框架之前的某个地方,因此屏蔽路径是一个更长的帧.尝试将代码移动到viewDidLayoutSubviews.