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];
        }];
    }
  • 相关阅读:
    css整理-06 表和列表
    css整理-05 边框,背景和浮动,定位
    css整理-04 基本视觉格式化
    css整理-03 文本
    css整理-02 颜色和字体
    no-jquery 05 Utilities
    no-jquery 04 Events
    使用nodejs写个服务器小程序
    快速判断数组中每个对象同一属性值是否相同
    飞快验证对象是否为空
  • 原文地址:https://www.cnblogs.com/cnman/p/4986607.html
Copyright © 2011-2022 走看看