iOS 04、iOS实现从下面弹出视图popView工具类

实现自下而上的弹出视图popView,包含动画效果,封装了一个简易的类,可以直接使用,本文章简易介绍一个封装类使用:
1.使用工具类实现弹出视图的功能

//弹出视图工具类的调用----单例模式,_popView为你要弹出的视图, animated为是否为这个视图添加动画效果,工具类中都有相应的处理,可以按需定制
[[YGPopUpTool sharedYGPopUpTool] popUpWithPresentView:_popView animated:YES];

2.使用工具类实现关闭弹出视图的功能

//关闭弹出视图工具类的调用
[[YGPopUpTool  sharedYGPopUpTool] closeWithBlock:nil];

提供一个我使用YGPopUpViewTool工具类弹出视图的一个实现文件的部分代码可供参考:

#import "ViewController.h"
#import "YGPopUpTool.h"

#define YGHeight [UIScreen mainScreen].bounds.size.height
#define YGWidth  [UIScreen mainScreen].bounds.size.width

@interface ViewController ()
@property (strong, nonatomic) UIView *popView;
@property (strong, nonatomic) UIButton *popBtn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    _popView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, YGWidth, 350)];
    _popView.backgroundColor = [UIColor clearColor];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(100, 200, 100, 50);
    btn.backgroundColor = [UIColor greenColor];
    [btn addTarget:self action:@selector(popViewShow) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    _popBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _popBtn.frame = CGRectMake(0, 250, 200, 50);
    _popBtn.backgroundColor = [UIColor greenColor];
    [_popBtn setTitle:@"PPOP" forState:UIControlStateNormal];
    [_popBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_popBtn addTarget:self action:@selector(closeAndBack) forControlEvents:UIControlEventTouchUpInside];
}
- (void)popViewShow {
    NSLog(@"dian le PPOP");
    UIImageView *imageV = [[UIImageView alloc]initWithFrame:_popView.bounds];
    imageV.image = [UIImage imageNamed:@"show"];
    [_popView addSubview:imageV];

    [[YGPopUpTool sharedYGPopUpTool] popUpWithPresentView:_popView animated:YES];
    
}

- (void)closeAndBack {
    [[YGPopUpTool  sharedYGPopUpTool] closeWithBlock:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}
@end

这个工具类写的时候很多地方有作相应的标记和注释,如果有不对的,或者更好的写法,麻烦告知,随时沟通,互相进步,谢谢!
完整使用工具类的demo代码链接:https://github.com/YGEqual/YGPopView/

你可能感兴趣的:(iOS 04、iOS实现从下面弹出视图popView工具类)