zoukankan      html  css  js  c++  java
  • iOS弹出底部视图简单实现

    - 项目基本目录

    其中xib文件用来自定义需要弹出的视图。

    在主控制器里设置popview的frame等信息代码如下:

    底部视图(popview)初始化放在父类视图的最顶部或者说是整个屏幕的最底部,宽高自定义

    - (void)viewDidLoad {
        [super viewDidLoad];
        _popview = [[popview alloc]init];
        _popview.frame = CGRectMake(0, self.view.frame.size.height, 400, 700);
        [self.view addSubview:_popview];
    }

    当点击相应按钮的时候让底部视图往上移

    - (IBAction)pop:(id)sender {
     
       [ UIView animateWithDuration:0.3 animations:^{
           CGAffineTransform tf = CGAffineTransformMakeTranslation(0, -_popview.frame.size.height);
           [_popview setTransform:tf];
        }];
    }

     popview视图中的代码如下:

    @interface popview ()
    
    @property (weak, nonatomic) IBOutlet UIView *bkview;
    
    @end
    
    @implementation popview
    
    - (instancetype)init{
       //从xib中初始化视图
        if (self = [super init]) {
            NSArray *binview = [[NSBundle mainBundle] loadNibNamed:@"popview" owner:nil options:nil];
            self = [binview lastObject];
        }
        return self;
    }
    //点击取消按钮的时候移除并且让弹出视图的背景视图隐藏,等到底部视图彻底移到底部的时候在设置显示背景视图(背景视图主要用来模糊效果)
    - (IBAction)cancel:(id)sender {
        [_bkview setHidden:YES];
       
        [UIView animateWithDuration:0.3 animations:^{
            self.transform =  CGAffineTransformIdentity;
            
        } completion:^(BOOL finished) {
            [_bkview setHidden:NO];
        }];
    }
  • 相关阅读:
    meta标签总结
    基本类型String的原生方法详解
    对JSON的增删查改
    百分比宽度div如何水平居中
    【转】Chrome 控制台console的用法(提高js调试能力)
    css textarea固定大小滚动条自动
    【转】前端必读:浏览器内部工作原理
    git clone 远程分支
    http-server 使用介绍
    js 全选/取消
  • 原文地址:https://www.cnblogs.com/cnman/p/4986607.html
Copyright © 2011-2022 走看看