iOS App中添加半透明新手指引

先看效果圖

這個是矩形
這個是矩形
這個是圓形
這個是圓形

基本思路就是在一個View 上加上蒙版 msak 。不貼代碼的都是流氓,So ,代碼如下:

#pragma mark - ===== 新手指引 =====

/**
 *  新手指引
 */
 
- (void)newUserGuide
{

    // 這里創建指引在這個視圖在window上
    CGRect frame = [UIScreen mainScreen].bounds;
    UIView * bgView = [[[UIView alloc]initWithFrame:frame]autorelease];
    bgView.backgroundColor = HEX_RGBA(0x323232, 0.8);
    UITapGestureRecognizer * tap = [[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sureTapClick:)]autorelease];
    [bgView addGestureRecognizer:tap];
    [[UIApplication sharedApplication].keyWindow addSubview:bgView];
    
    //create path 重點來了(**這里需要添加第一個路徑)
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:frame];   
    // 這里添加第二個路徑 (這個是圓)
    [path appendPath:[UIBezierPath bezierPathWithArcCenter:CGPointMake(frame.size.width - 30, 42) radius:30 startAngle:0 endAngle:2*M_PI clockwise:NO]]; 
    // 這里添加第二個路徑 (這個是矩形)
    //[path appendPath:[[UIBezierPath bezierPathWithRoundedRect:CGRectMake(frame.size.width/2.0-1, 234, frame.size.width/2.0+1, 55) cornerRadius:5] bezierPathByReversingPath]];
    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.path = path.CGPath;
    //shapeLayer.strokeColor = [UIColor blueColor].CGColor;
    [bgView.layer setMask:shapeLayer];  
    UIImageView * imageView = [[[UIImageView alloc]initWithFrame:CGRectMake(frame.size.width -300,72,270, 137)]autorelease];
    imageView.image = [UIImage imageNamed:@"CouponBoard_guid"];
    [bgView addSubview:imageView];
    
} 


/**
 *   新手指引確定
 */
- (void)sureTapClick:(UITapGestureRecognizer *)tap
{
    UIView * view = tap.view;
    [view removeFromSuperview];
    [view removeAllSubviews];
    [view removeGestureRecognizer:tap];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstCouponBoard_iPhone"];
}

其他方法自行google 這里推薦一個博文 提供不同思路。

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,098評論 25 708
  • 楊邁勇閱讀 175評論 0 1
  • “好了,查克,我要向你解釋一些事情。你的工作職責是讓客戶認為他是房間里最聰明的人。如果你完成了這項任務之后還有多余...
    CSir205閱讀 241評論 0 0