溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

iOS新功能引導(dǎo)提示界面的示例分析

發(fā)布時(shí)間:2021-07-10 11:09:06 來源:億速云 閱讀:187 作者:小新 欄目:移動開發(fā)

這篇文章主要介紹了iOS新功能引導(dǎo)提示界面的示例分析,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

首先看下效果圖:

iOS新功能引導(dǎo)提示界面的示例分析

1.首先創(chuàng)建第一個(gè)viewcontroller 在上面放上一個(gè)imageview和一個(gè)按鈕

- (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.這時(shí)候我們在創(chuàng)建一個(gè)BackViewController 設(shè)置透明即可

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

這里提示一點(diǎn),很多時(shí)候我們對視圖直接設(shè)置alpha屬性的值會導(dǎo)致其子控件也變得半透明,而通常我們的需求是:背景半透明而其子控件不透明。

因此我們可以用一下方法設(shè)置透明度

//只設(shè)置黑白背景色 white后面的參數(shù)表示灰度,從0-1之間表示從黑到白的變化,alpha就是你想調(diào)整的透明度。
  blackV.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7]; 
//設(shè)置任意顏色的背景色
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.設(shè)置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=@"這是新功能";
  titlelabel.textColor=[UIColor whiteColor];
}
-(void)btnclick
{
  [self dismissViewControllerAnimated:YES completion:nil];
}

原理很簡單,我們present出來一個(gè)透明的控制器,這樣在控制器上面放上幾個(gè)深度alpha的view和一個(gè)btn,哦,還需要一個(gè)label提示文字,也可以自己再添加一些箭頭什么的,當(dāng)然這個(gè)btn時(shí)美工扣圖處理之后給你的,然后通過改變它們的frame來實(shí)現(xiàn)不同位置的提示。因?yàn)槭亲龅膁emo所以我用了frame,我建議用autolayout去定它們之間的關(guān)系,然后用transform來實(shí)現(xiàn)移動frame,然后可以提示多個(gè)新功能。

btn摳圖之后的效果:

iOS新功能引導(dǎo)提示界面的示例分析

感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“iOS新功能引導(dǎo)提示界面的示例分析”這篇文章對大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

ios
AI