IOS实现弹出菜单效果MenuViewController(背景 景深 弹出菜单)

在写项目时,要实现一个从下移上来的一个弹出菜单,并且背景变深的这么一个效果,在此分享给大家。

主要说一下思路及一些核心代码贴出来,要想下载源码,

请到:http://download.csdn.net/download/rhljiayou/6280989

一个简单,效果好,比较实用的菜单弹出效果的实现,效果图:

实现方式:将self.view当前页面缩小,在当前页的上面添加一个菜单的view,即在self.view.superview添加。

[cpp] view plaincopy
 
  1. //显示  
  2. - (void) show:(UIView*)parent  
  3. {  
  4.     parentView = parent;  
  5.       
  6.     //先隐藏backView,table  
  7.     backView.alpha = 0;  
  8.     _table.alpha = 0;  
  9.       
  10.     //移动table  
  11.     [_table setTransform:CGAffineTransformMakeTranslation(0, _table.frame.size.height)];  
  12.       
  13.     //父窗口添加本view,---这个会调用viewDidLoad  
  14.     [parentView.superview addSubview:self.view];  
  15.       
  16.     //添加动画,添加到父窗口中,使之从下移动上  
  17.     [UIView animateWithDuration:0.3 animations:^{  
  18.         //父窗口缩小  
  19.         CGAffineTransform t = CGAffineTransformMakeScale(0.9, 0.9);  
  20.         [parentView setTransform:t];  
  21.           
  22.         //显示backview,table  
  23.         backView.alpha = 1;  
  24.         _table.alpha = 1;  
  25.           
  26.         //移动table,CGAffineTransformIdentity还原原始坐标  
  27.         [_table setTransform:CGAffineTransformIdentity];  
  28.   
  29.     } completion:^(BOOL finished) {  
  30.           
  31.     }];  
  32.       
  33.       
  34. }  
  35. //隐藏  
  36. - (void) hide  
  37. {  
  38.     //添加动画,添加到父窗口中,使之从下移动上  
  39.     [UIView animateWithDuration:0.3 animations:^{  
  40.         //父窗口还原   
  41.         CGAffineTransform t = CGAffineTransformIdentity;  
  42.         [parentView setTransform:t];  
  43.           
  44.         //显示backview,table  
  45.         backView.alpha = 0;  
  46.         _table.alpha = 0;  
  47.           
  48.         //移动table  
  49.         [_table setTransform:CGAffineTransformMakeTranslation(0, _table.frame.size.height)];  
  50.           
  51.     } completion:^(BOOL finished) {  
  52.         [self.view removeFromSuperview];  
  53.     }];  
  54. }  
  55.   
  56. - (void)viewDidLoad  
  57. {  
  58.     [super viewDidLoad];  
  59.       
  60.     self.view.backgroundColor = [UIColor clearColor];  
  61.       
  62.     //背影黑罩  
  63.     backView = [[UIView alloc]initWithFrame:self.view.bounds];  
  64.     backView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];  
  65.     [self.view addSubview:backView];  
  66.       
  67.     //算出table的CGRect  
  68.     CGRect rect = self.view.bounds;  
  69.     int height = _titleArray.count * 44;  
  70.     rect.origin.y = rect.size.height - height;  
  71.     rect.size.height = height;  
  72.       
  73.     _table = [[UITableView alloc]initWithFrame:rect];  
  74.     _table.delegate = self;  
  75.     _table.dataSource = self;  
  76.     [self.view addSubview:_table];  
  77.   
  78. }  

转载地址 : http://blog.csdn.net/rhljiayou/article/details/11768963 

这个菜单你可以任意自定义,我这里是一个tableView,你可以写一些有图和文字的添加上去。只需要把源代码稍改,就ok!

原文地址:https://www.cnblogs.com/wcLT/p/4733631.html