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中的按钮触发

  • 相关阅读:
    java 代码 添加控件 修改位置 View
    获取整个Activity的layout
    线程加锁 同步
    应用内悬浮按钮 可吸附 展开有动画 mini播放器
    svg 动画
    动画之二:属性动画 Property Animation
    ButterKnife 免去findviewby的麻烦
    ImageView 控件的宽高随图片变化
    python pip使用国内镜像安装第三方库:命令行或PyCharm
    pycharm安装pika提示CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://repo.anaconda.com>
  • 原文地址:https://www.cnblogs.com/h-tao/p/5635377.html
Copyright © 2011-2022 走看看