
弹出动画
**下拉菜单是非常常用的一个功能,这里封装了一个自带动画下拉菜单 **。
- 构建方法
 
 /**
 *  构建方法
 *  param array   标题
 *  每行默认高度40
 */
 -(instancetype)initWithFrame:(CGRect)frame withTitleArray:(NSArray<NSString *> *)array;
根据传入的array来创建列表,需要注意的是,每次添加后,都需要手动调用beginAnimation方法来做动画。移除时调用dismiss方法,button点击方法如下如下:
if ([self.view viewWithTag:1])
    {
        [self.menuView dismiss];
    }
    else
    {
        [self.view addSubview:self.menuView];
        [self.menuView beginAnimation];
    }
点击使用block来进行回调
self.menuView.clickBlock = ^(NSInteger tag){
        UIAlertAction *action =[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:weakSelf.dataArray[tag] preferredStyle:UIAlertControllerStyleAlert];
        [alert addAction:action];
        [weakSelf presentViewController:alert animated:YES completion:nil];
    };
关于动画的实现
使用UIView动画usingSpringWithDamping,并且根据每个动画时间根据tag递增,使其有弹的效果,代码如下:
[UIView animateWithDuration:0.3 + 0.05 * idx
                              delay:0.1
             usingSpringWithDamping:0.9
              initialSpringVelocity:1
                            options:UIViewAnimationOptionCurveEaseIn
                         animations:^{
                             btn.frame      = CGRectMake(10, idx * 40 + 15, 130, 40 - 0.3);
                             line.frame     = CGRectMake(10, idx * 40 + 39.7 + 15, self.bgFrame.size.width - 20, 0.3);
                         }
                         completion:^(BOOL finished) {
                             
                         }];
消失的动画与开始动画类似
代码连接gitHub