制作半透明引导页

效果图 2016年12月12日 下午6.33.21.png
- (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;
    }
    
}

其他参看:http://www.jianshu.com/p/b83aefdc9519

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容