//调用
if ( ![[NSUserDefaults standardUserDefaults] boolForKey:@"firstCouponBoard_iPhone_0"]) {
[self newUserGuide:CGRectMake(15,260, ScreenW/2.0-30,90) imgFrame:CGRectMake(0, 350, ScreenW, 243) imgName:@"newUserGuide_0" viewTag:0];
}
#pragma mark - ===== 新手指引 =====
- (void)newUserGuide:(CGRect)rectFrame imgFrame:(CGRect)imgFrame imgName:(NSString *)imgName viewTag:(NSInteger)vTag;
{
// 这里创建指引在这个视图在window上
CGRect frame = [UIScreen mainScreen].bounds;
UIView * bgView = [[UIView alloc]initWithFrame:frame];
bgView.tag = vTag;
bgView.backgroundColor = RGBColor(0, 0, 0, 0.6);
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sureTapClick:)];
[bgView addGestureRecognizer:tap];
[[UIApplication sharedApplication].keyWindow addSubview:bgView];
//create path 重点来了(**这里需要添加第一个路径)
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:rectFrame cornerRadius:10] bezierPathByReversingPath]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[bgView.layer setMask:shapeLayer];
UIImageView * imageView = [[UIImageView alloc]initWithFrame:imgFrame];//
imageView.image = [UIImage imageNamed:imgName];
imageView.contentMode = UIViewContentModeScaleAspectFit;//UIViewContentModeCenter;//
[bgView addSubview:imageView];
}
/**
* 新手指引确定
*/
- (void)sureTapClick:(UITapGestureRecognizer *)tap
{
UIView * view = tap.view;
[view removeFromSuperview];
[view removeGestureRecognizer:tap];
if (view.tag == 0) {
[self newUserGuide:CGRectMake(ScreenW/2.0+15,260, ScreenW/2.0-30,90) imgFrame:CGRectMake(0,350, ScreenW, 243) imgName:@"newUserGuide_1" viewTag:1];
}else if (view.tag == 1){
[self newUserGuide:CGRectMake(15, 420, ScreenW-30,90) imgFrame:CGRectMake(0, 298, ScreenW, 305) imgName:@"newUserGuide_2" viewTag:2];
}else if (view.tag == 2){
[self newUserGuide:CGRectMake(10, 510, 110,74) imgFrame:CGRectMake(0, 384, ScreenW, 140) imgName:@"newUserGuide_3" viewTag:3];
}else if (view.tag == 3){
[self newUserGuide:CGRectMake(0, ScreenH-TabbarHeight, ScreenW,TabbarHeight) imgFrame:CGRectMake(0, ScreenH-TabbarHeight-237, ScreenW, 237) imgName:@"newUserGuide_4" viewTag:4];
} else{
UIView * view = tap.view;
[view removeFromSuperview];
[view removeGestureRecognizer:tap];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstCouponBoard_iPhone_0"];
}
}
网友评论