
效果圖 2016年12月12日 下午6.33.21.png
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//有數(shù)據(jù)才加載半透明引導(dǎo)頁
if (self.ZSDdealArrItem.count != 0) {
[self loadFirstGuide];
}
}
#pragma mark - 添加引導(dǎo)頁
- (void)loadFirstGuide{
//只要app沒刪除,只加載一次
NSString *isFirst = [self readFirstGuideLocatData];
if (isFirst) {
return;
}
//創(chuàng)建灰色蒙版
CGRect frame = CGRectMake(0, 0, yxxScreenWidth, yxxScreenHeight);
UIView *blackView = [[UIView alloc] initWithFrame:frame];
blackView.backgroundColor = [UIColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:0.5];
[self.view.window insertSubview:blackView aboveSubview:self.tableView];
// 添加小藍(lán)人圖片
UIImageView *ydImageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 105, 140, 120)];
[blackView addSubview:ydImageView];
ydImageView.image = [UIImage imageNamed:@"tfb_yd_arrow"];
//添加手勢(shì)
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(blackViewTap:)];
[blackView addGestureRecognizer:tap];
//重點(diǎn)來了, 這里需要添加路徑
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
// 這個(gè)是矩形
[path appendPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 115, 150, 30)] bezierPathByReversingPath]];
//渲染
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[blackView.layer setMask:shapeLayer];
//存儲(chǔ)數(shù)據(jù),防止下次展示引導(dǎo)頁
[self initAFileWithDictionary:@{@"isFirst" : @"1"}];
}
#pragma mark - 移除引導(dǎo)頁
- (void)blackViewTap:(UITapGestureRecognizer *)tap{
for (int i = 0; i < tap.view.subviews.count; i++) {//移除所有子視圖
[tap.view.subviews[i] removeFromSuperview];
}
[tap.view removeFromSuperview];//移除蒙版
[tap.view removeGestureRecognizer:tap];//移除手勢(shì)
}
#pragma mark - 數(shù)據(jù)存儲(chǔ)
//存數(shù)據(jù)
- (void)initAFileWithDictionary:(NSDictionary *)dict {
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"zsdYd.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] == NO) {
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:path contents:nil attributes:nil];
}
BOOL isArchive = [NSKeyedArchiver archiveRootObject:dict toFile:path];
}
//取數(shù)據(jù)
- (NSString *)readFirstGuideLocatData{
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"zsdYd.plist"];
// 讀取文件內(nèi)容
NSDictionary *dataDictionary =[NSKeyedUnarchiver unarchiveObjectWithFile:path];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] && dataDictionary != nil) { // 本地有數(shù)據(jù)
NSLog(@"已經(jīng)創(chuàng)建了這個(gè)文件,并且文件內(nèi)容不為空");
return dataDictionary[@"isFirst"];
} else { // 本地?zé)o數(shù)據(jù),則顯示默認(rèn)
return nil;
}
}