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];
        }];
    }
  • 相关阅读:
    委托的BeginInvoke和EndInvoke
    HTTP Post
    显示一个托盘
    sql语句
    在C++ 中 如何调用 C# 写的DLL(转载)
    WinForm-MenuStrip
    rsync定时同步和rsync+sersync实时同步
    innobackupex自动备份数据库脚本
    innobackupex备份恢复mysql
    gitlab安装和基本使用
  • 原文地址:https://www.cnblogs.com/cnman/p/4986607.html
Copyright © 2011-2022 走看看