制作半透明引導(dǎo)頁

效果圖 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;
    }
    
}

其他參看:http://www.itdecent.cn/p/b83aefdc9519

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容