先看效果图
这个是矩形 这个是矩形 这个是圆形 这个是圆形基本思路就是在一个View 上加上蒙版 msak 。不贴代码的都是流氓,So ,代码如下:
#pragma mark - ===== 新手指引 =====
/**
* 新手指引
*/
- (void)newUserGuide
{
// 这里创建指引在这个视图在window上
CGRect frame = [UIScreen mainScreen].bounds;
UIView * bgView = [[[UIView alloc]initWithFrame:frame]autorelease];
bgView.backgroundColor = HEX_RGBA(0x323232, 0.8);
UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sureTapClick:)]autorelease];
[bgView addGestureRecognizer:tap];
[[UIApplication sharedApplication].keyWindow addSubview:bgView];
//create path 重点来了(**这里需要添加第一个路径)
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
// 这里添加第二个路径 (这个是圆)
[path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(frame.size.width - 30, 42) radius:30 startAngle:0 endAngle:2*M_PI clockwise:NO]];
// 这里添加第二个路径 (这个是矩形)
//[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(frame.size.width/2.0-1, 234, frame.size.width/2.0+1, 55) cornerRadius:5] bezierPathByReversingPath]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
//shapeLayer.strokeColor = [UIColor blueColor].CGColor;
[bgView.layer setMask:shapeLayer];
UIImageView * imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width -300,72,270, 137)]autorelease];
imageView.image = [UIImage imageNamed:@"CouponBoard_guid"];
[bgView addSubview:imageView];
}
/**
* 新手指引确定
*/
- (void)sureTapClick:(UITapGestureRecognizer *)tap
{
UIView * view = tap.view;
[view removeFromSuperview];
[view removeAllSubviews];
[view removeGestureRecognizer:tap];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstCouponBoard_iPhone"];
}
其他方法自行google 这里推荐一个博文 提供不同思路。
网友评论
在appendPath方法中能否添加自定义路径(用UIBezierPath画的不规则图形)呢?
我自己尝试了下,貌似不行...
frame+rect(Reverse)的路径如果是你所说的效果,那我理解frame+rect应该是rect部分绘制,其他剩余部分镂空了
多调用这句 把frame替换就可以了
#pragma mark - === UIColor定义的宏 ===
#undef RGB
#define RGB(R,G,B) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:1.0f]
#undef RGBA
#define RGBA(R,G,B,A) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:A]
#undef HEX_RGB
#define HEX_RGB(V) [UIColor fromHexValue:V]
#undef HEX_RGBA
#define HEX_RGBA(V, A) [UIColor fromHexValue:V alpha:A]
#undef SHORT_RGB
#define SHORT_RGB(V) [UIColor fromShortHexValue:V]