- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
//有数据才加载半透明引导页
if (self.ZSDdealArrItem.count != 0) {
[self loadFirstGuide];
}
}
#pragma mark - 添加引导页
- (void)loadFirstGuide{
//只要app没删除,只加载一次
NSString *isFirst = [self readFirstGuideLocatData];
if (isFirst) {
return;
}
//创建灰色蒙版
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];
// 添加小蓝人图片
UIImageView *ydImageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 105, 140, 120)];
[blackView addSubview:ydImageView];
ydImageView.image = [UIImage imageNamed:@"tfb_yd_arrow"];
//添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(blackViewTap:)];
[blackView addGestureRecognizer:tap];
//重点来了, 这里需要添加路径
UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];
// 这个是矩形
[path appendPath:[[UIBezierPath bezierPathWithOvalInRect:CGRectMake(5, 115, 150, 30)] bezierPathByReversingPath]];
//渲染
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = path.CGPath;
[blackView.layer setMask:shapeLayer];
//存储数据,防止下次展示引导页
[self initAFileWithDictionary:@{@"isFirst" : @"1"}];
}
#pragma mark - 移除引导页
- (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];//移除手势
}
#pragma mark - 数据存储
//存数据
- (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];
}
//取数据
- (NSString *)readFirstGuideLocatData{
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"zsdYd.plist"];
// 读取文件内容
NSDictionary *dataDictionary =[NSKeyedUnarchiver unarchiveObjectWithFile:path];
if ([[NSFileManager defaultManager] fileExistsAtPath:path] && dataDictionary != nil) { // 本地有数据
NSLog(@"已经创建了这个文件,并且文件内容不为空");
return dataDictionary[@"isFirst"];
} else { // 本地无数据,则显示默认
return nil;
}
}
制作半透明引导页
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 北京时间10月2日,据《圣何塞水星新闻》报道,昨天勇士与掘金的季前赛开始之前,4届最佳防守球员本-华莱士把上赛季的...