zoukankan      html  css  js  c++  java
  • 上拉式弹窗的实现

      有些弹窗如果点击按钮的同时就出现一个弹窗就显得有的突兀,这次实现的效果是点击按钮的同时弹窗由下往上弹出来,添加了动画效果:

    1、首先创建一个弹出的View类,

    在HTAlertView.h中:

    @property (nonatomic, strong) void (^backBtnActionBlock)();
    
    @property (weak, nonatomic) IBOutlet UIView *myView;
    
    @property(nonatomic,strong) UIControl *huiseControl;
    
    - (void)showInView:(UIView *) view;
    
    + (instancetype)getSimpleView;
    

    2、在HTAlertView.m中:

    - (void)awakeFromNib{
        
        _huiseControl=[[UIControl alloc]initWithFrame:CGRectMake(0, 0, UIBounds.size.width, UIBounds.size.height)];
        _huiseControl.backgroundColor=RGBACOLOR(0, 0, 0, 0.4);
        [_huiseControl addTarget:self action:@selector(huiseControlClick) forControlEvents:UIControlEventTouchUpInside];
        _huiseControl.alpha=0;
        self.backgroundColor = [UIColor whiteColor];
    }
    
    + (instancetype)getSimpleView{
        
        NSArray *objs = [[NSBundle mainBundle] loadNibNamed:@"HTAlertView" owner:nil options:nil];
        return [objs lastObject];
    }
    - (void)showInView:(UIView *) view {
    
        if (_huiseControl.superview==nil) {
            [view addSubview:_huiseControl];
        }
        [UIView animateWithDuration:0.2 animations:^{
            _huiseControl.alpha=1;
        }];
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.2f;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromTop;
        [self.layer addAnimation:animation forKey:@"animation1"];
        self.frame = CGRectMake(0,view.frame.size.height - 355, [UIScreen mainScreen].bounds.size.width, 355);
        [view addSubview:self];
    
    }
    - (void)hideInView {
        
        self.hidden = YES;
        CATransition *animation = [CATransition  animation];
        animation.delegate = self;
        animation.duration = 0.2f;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        animation.type = kCATransitionPush;
        animation.subtype = kCATransitionFromBottom;
        [self.layer addAnimation:animation forKey:@"animtion2"];
        [UIView animateWithDuration:0.2 animations:^{
            _huiseControl.alpha=0;
        }completion:^(BOOL finished) {
            [self removeFromSuperview];
            [_huiseControl removeFromSuperview];
        }];
       
    }
    - (IBAction)btnClick:(UIButton *)sender {
        
        if (self.backBtnActionBlock) {
            
            self.backBtnActionBlock();
        }
    }
    
    -(void)huiseControlClick{
        
        [self hideInView];
    }
    

    其中

    #define UIBounds [[UIScreen mainScreen] bounds] //window外框大小
    #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:a]
    

    最后在viewController中要弹窗的button实现方法即可

    - (void)popupButtonClick
    {
        HTAlertView *alert = [HTAlertView getSimpleView];
        
        alert.backBtnActionBlock = ^(){
          
            NSLog(@"sdgvet4wfdscx");
        };
        
        [alert showInView:self.view];
    }
    

     其中有代码块可以回调得到View中的按钮触发

  • 相关阅读:
    away3d 4.1 alpha 教程 换装篇 <3> 人物动态换装DEMO
    书本资料汇总
    洪小瑶学IOS(一):准备起航 <ObjectiveC基础教程>笔记
    Flex 4 权威指南 学习笔记
    通过存储过程建立灵活的SQL计划任务
    javascript 未结束的字符串常量
    SQL重复记录查询
    重置数据库自增字段
    C#获取周一、周日的日期 函数类
    C# ,ASP.NET,Winform将数据导出到Execl汇总
  • 原文地址:https://www.cnblogs.com/h-tao/p/5635377.html
Copyright © 2011-2022 走看看