在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家。
主要说一下思路及一些核心代码贴出来,要想下载源码,请点击下载:menuviewcontroller
一个简单,效果好,比较实用的菜单弹出效果的实现,效果图:
![ios uiviewcontroller(ios menuviewcontroller实现弹","p":true,"g":[{"type":"sug","sa":"s_1","q":"ios uiviewcontroller"}],"slid":"98348533964230","](/zb_users/upload/2022/10/160434B58-0.jpg)
实现方式:将self.view当前页面缩小,在当前页的上面添加一个菜单的view,即在self.view.superview添加。
?| 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
//显示
- (void) show:(uiview*)parent
{
parentview = parent;
//先隐藏backview,table
backview.alpha = 0;
_table.alpha = 0;
//移动table
[_table settransform:cgaffinetransformmaketranslation(0, _table.frame.size.height)];
//父窗口添加本view,---这个会调用viewdidload
[parentview.superview addsubview:self.view];
//添加动画,添加到父窗口中,使之从下移动上
[uiview animatewithduration:0.3 animations:^{
//父窗口缩小
cgaffinetransform t = cgaffinetransformmakescale(0.9, 0.9);
[parentview settransform:t];
//显示backview,table
backview.alpha = 1;
_table.alpha = 1;
//移动table,cgaffinetransformidentity还原原始坐标
[_table settransform:cgaffinetransformidentity];
} completion:^(bool finished) {
}];
}
//隐藏
- (void) hide
{
//添加动画,添加到父窗口中,使之从下移动上
[uiview animatewithduration:0.3 animations:^{
//父窗口还原
cgaffinetransform t = cgaffinetransformidentity;
[parentview settransform:t];
//显示backview,table
backview.alpha = 0;
_table.alpha = 0;
//移动table
[_table settransform:cgaffinetransformmaketranslation(0, _table.frame.size.height)];
} completion:^(bool finished) {
[self.view removefromsuperview];
}];
}
- (void)viewdidload
{
[super viewdidload];
self.view.backgroundcolor = [uicolor clearcolor];
//背影黑罩
backview = [[uiview alloc]initwithframe:self.view.bounds];
backview.backgroundcolor = [uicolor colorwithred:0 green:0 blue:0 alpha:0.3];
[self.view addsubview:backview];
//算出table的cgrect
cgrect rect = self.view.bounds;
int height = _titlearray.count * 44;
rect.origin.y = rect.size.height - height;
rect.size.height = height;
_table = [[uitableview alloc]initwithframe:rect];
_table.delegate = self;
_table.datasource = self;
[self.view addsubview:_table];
}
|
这个菜单你可以任意自定义,我这里是一个tableview,你可以写一些有图和文字的添加上去。只需要把源代码稍改,就ok!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:http://252190908.iteye.com/blog/1994807








发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。