相关疑难解决方法(0)

UIBezierPath减去路径

通过使用[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:],我可以创建一个圆形视图,如下所示:

圆形视图

我怎样才能从这一个(或其他方式)中减去另一条路径,以创建这样的路径:

减去视图

我有什么方法可以做这样的事情吗?伪代码:

UIBezierPath *bigMaskPath = [UIBezierPath bezierPathWithRoundedRect:bigView.bounds 
                                 byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
                                       cornerRadii:CGSizeMake(18, 18)];
UIBezierPath *smallMaskPath = [UIBezierPath bezierPathWithRoundedRect:smalLView.bounds 
                                     byRoundingCorners:(UIRectCornerTopLeft|UIRectCornerTopRight)
                                           cornerRadii:CGSizeMake(18, 18)];

UIBezierPath *finalPath = [UIBezierPath pathBySubtractingPath:smallMaskPath fromPath:bigMaskPath];
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uibezierpath

47
推荐指数
6
解决办法
3万
查看次数

用另一个CALayer屏蔽CALayer

我正试图用CALayers制作甜甜圈.一个CALayer将是一个大圆圈,另一个将是一个位于其中心的较小圆圈,掩盖它.

大圆圈显示正常,但每当我打电话时circle.mask = circleMask;,视图显示为空.

这是我的代码:

AriDonut.h

#import <UIKit/UIKit.h>

@interface AriDonut : UIView
-(id)initWithRadius:(float)radius;
@end
Run Code Online (Sandbox Code Playgroud)

AriDonut.m

#import "AriDonut.h"
#import <QuartzCore/QuartzCore.h>

@implementation AriDonut

-(id)initWithRadius:(float)radius{
    self = [super initWithFrame:CGRectMake(0, 0, radius, radius)];
    if(self){

        //LARGE CIRCLE
        CALayer *circle = [CALayer layer];
        circle.bounds = CGRectMake(0, 0, radius, radius);
        circle.backgroundColor = [UIColor redColor].CGColor;
        circle.cornerRadius = radius/2;
        circle.position = CGPointMake(radius/2, radius/2);

        //SMALL CIRLCE
        CALayer *circleMask = [CALayer layer];
        circleMask.bounds = CGRectMake(0, 0, 10, 10);
        circleMask.cornerRadius = radius/2;
        circleMask.position = circle.position;

        //circle.mask = circleMask;

        [self.layer addSublayer:circle]; …
Run Code Online (Sandbox Code Playgroud)

core-animation calayer uiview ios

14
推荐指数
3
解决办法
2万
查看次数