在开发中,现在很多app更新了新功能时都会给出用户一个提示,以方便用户更好的体验,那么这个功能如何实现的呢?
首先看下效果图:
1.首先创建第一个viewcontroller 在上面放上一个imageview和一个按钮
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
- ( 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 设置透明即可
1
2
3
4
5
6
7
8
9
10
|
- (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属性的值会导致其子控件也变得半透明,而通常我们的需求是:背景半透明而其子控件不透明。
因此我们可以用一下方法设置透明度
1
2
3
4
5
6
|
//只设置黑白背景色 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上面的控件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
- ( 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出来一个透明的控制器,这样在控制器上面放上几个深度alpha的view和一个btn,哦,还需要一个label提示文字,也可以自己再添加一些箭头什么的,当然这个btn时美工扣图处理之后给你的,然后通过改变它们的frame来实现不同位置的提示。因为是做的demo所以我用了frame,我建议用autolayout去定它们之间的关系,然后用transform来实现移动frame,然后可以提示多个新功能。
btn抠图之后的效果:
以上所述是小编给大家介绍的ios新功能引导提示界面实例详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://blog.csdn.net/qq_29892943/article/details/70745869