IOS APP新手指南
2017-10-13 本文已影响0人
huhuhuhu123
// 判断是否加载过新手指南
NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
BOOL isADD = [user objectForKey:@"secondCouponBoard_iPhone"];
if (isADD != YES) {
[self newUserGuide];
}
#pragma mark - ===== 新手指引 =====
/**
* 新手指引
*/
- (void)newUserGuide
{
// 这里创建指引在这个视图在window上
CGRect frame = [UIScreen mainScreen].bounds;
// 把背景view添加到window上边
UIView * bgView = [[UIView alloc] initWithFrame:frame];
[bgView setBackgroundColor:[UIColor clearColor]];
[[UIApplication sharedApplication].keyWindow addSubview:bgView];
// 添加背景图片 并在背景图片上边添加轨迹
UIImageView * bgImg = [[UIImageView alloc] initWithFrame:frame];
[bgImg setBackgroundColor:[UIColor blackColor]];
bgImg.alpha = 0.6;
[bgView addSubview:bgImg];
//create path 重点来了(**这里需要添加第一个路径)
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
// 这里添加第二个路径 (这个是圆)
[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(13, 33, kWidth - 13* 2, 94) cornerRadius:5] bezierPathByReversingPath]];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[bgImg.layer setMask: shapeLayer];
// 添加指引图片
UIImageView * img = [[UIImageView alloc] init];
[img setFrame:CGRectMake((kWidth - 290) /2, 100, 290, 180)];
[img setImage:[UIImage imageNamed:@"guide_04"]];
[img setContentMode:UIViewContentModeScaleToFill];
[bgView addSubview:img];
// 添加点击事件
UIButton * newGuidBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[newGuidBtn setFrame:frame];
[newGuidBtn addTarget:self action:@selector(clickBtnToGuid:) forControlEvents:UIControlEventTouchUpInside];
[bgView addSubview:newGuidBtn];
}
- (void)clickBtnToGuid:(UIButton *)sender
{
// 点击之后移除到父类view
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"secondCouponBoard_iPhone"];
[sender.superview removeFromSuperview];
}