ios新功能引導提示

來源:互聯網
上載者:User

標籤:javascrip   參數表   lstat   提示   south   custom   ==   rect   cti   

在開發中,現在很多app更新了新功能時都會給出使用者一個提示,以方便使用者更好的體驗,那麼這個功能如何?的呢?
首先看下:

1.首先建立第一個viewcontroller 在上面放上一個imageview和一個按鈕

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view.    UIImageView *imageview=[[UIImageView alloc]init];    imageview.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);    imageview.image=[UIImage imageNamed:@"girl.png"];    [self.view addSubview:imageview];    UIButton *Btn=[[UIButton alloc]init];    Btn.frame=CGRectMake(20, 100, 50, 50);    Btn.backgroundColor=[UIColor blueColor];    [Btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];    [imageview addSubview:Btn];    imageview.userInteractionEnabled=YES;}-(void)btnclick{    BackViewController *backVc=[[BackViewController alloc]init];    [self presentViewController:backVc animated:YES completion:nil];}

2.這時候我們在建立一個BackViewController 設定透明即可

- (instancetype)init{    self = [super init];    if (self) {        self.view.backgroundColor=[UIColor colorWithWhite:0 alpha:0.4];        self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;        self.modalPresentationStyle = UIModalPresentationOverFullScreen;    }    return self;}

這裡提示一點,很多時候我們對視圖直接設定alpha屬性的值會導致其子控制項也變得半透明,而通常我們的需求是:背景半透明而其子控制項不透明。
因此我們可以用一下方法設定透明度

//只設定黑白背景色 white後面的參數表示灰階,從0-1之間表示從黑到白的變化,alpha就是你想調整的透明度。    blackV.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];  //設定任意顏色的背景色blackV.backgroundColor = [UIColor colorWithRed:122/255.0 green:123/255.0 blue:234/255.0 alpha:0.7]; UIColor *color = [UIColor blackColor];bgView.backgroundColor = [color colorWithAlphaComponent:0.5];

3.設定BackViewController上面的控制項

- (void)viewDidLoad {    [super viewDidLoad];    UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];    btn.frame=CGRectMake(50, 300, 50, 50);//    btn.backgroundColor=[UIColor blueColor];    [self.view addSubview:btn];    [btn setBackgroundImage:[UIImage imageNamed:@"userGuideBtnBG_unClear.png"] forState:UIControlStateNormal];    [btn addTarget:self action:@selector(btnclick) forControlEvents:UIControlEventTouchUpInside];    btn.backgroundColor=[UIColor clearColor];    btn.alpha=0.75;    UIView *view1=[[UIView alloc]init];    view1.backgroundColor=[UIColor blackColor];    view1.alpha=0.75;    [self.view addSubview:view1];    view1.frame=CGRectMake(0, 0, self.view.frame.size.width, 300);    UIView *view2=[[UIView alloc]init];    view2.backgroundColor=[UIColor blackColor];    view2.alpha=0.75;    [self.view addSubview:view2];    view2.frame=CGRectMake(0, 300+50, self.view.frame.size.width, self.view.frame.size.height-50-300);    UIView *view3=[[UIView alloc]init];    view3.backgroundColor=[UIColor blackColor];    view3.alpha=0.75;    [self.view addSubview:view3];    view3.frame=CGRectMake(0, 300, 50, 50);    UIView *view4=[[UIView alloc]init];    view4.backgroundColor=[UIColor blackColor];    view4.alpha=0.75;    [self.view addSubview:view4];    view4.frame=CGRectMake(50+50, 300, self.view.frame.size.width-50-50, 50);    UILabel *titlelabel=[[UILabel alloc]init];    titlelabel.frame=CGRectMake(100, 350,100,50 );    [self.view addSubview:titlelabel];    titlelabel.text[email protected]"這是新功能";    titlelabel.textColor=[UIColor whiteColor];}-(void)btnclick{    [self dismissViewControllerAnimated:YES completion:nil];}

原理很簡單,我們present出來一個透明的控制器,這樣在控制器上面放上幾個深度alpha的view和一個btn,哦,還需要一個label提示文字,也可以自己再添加一些箭頭什麼的,當然這個btn時美工扣圖處理之後給你的,然後通過改變它們的frame來實現不同位置的提示。因為是做的demo所以我用了frame,我建議用autolayout去定它們之間的關係,然後用transform來實現移動frame,然後可以提示多個新功能。
btn摳圖之後的效果:

ios新功能引導提示

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.