PopView

作者: 阿龍飛 | 来源:发表于2020-08-11 16:06 被阅读0次

底部弹窗

//
//  MyPopView.h
//  text
//
//  Created by 123 on 2020/8/11.
//  Copyright © 2020 . All rights reserved.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

@interface MyPopView : UIView
///点背景关闭弹窗要加,否则可以去掉backgroundView,加是为了防止事件穿透,点击contentView不会关闭弹窗
@property(nonatomic,strong)UIView *backgroundView;

@property(nonatomic,strong)UIView *contentView;

- (void)show;

- (void)dismiss;

@property (copy, nonatomic) void (^touchSureBtnClickBlock)(void);

@property(nonatomic,strong)UIButton *sureBtn;

@end

NS_ASSUME_NONNULL_END

//
//  MyPopView.m
//  text
//
//  Created by 123 on 2020/8/11.
//  Copyright © 2020 . All rights reserved.
//

#import "MyPopView.h"
#import "Masonry.h"

@implementation MyPopView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        self.tag = 12000;
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)];
        [self.backgroundView addGestureRecognizer:tap];
        [self setUI];
        [self layout];
    }
    return self;
}

#pragma mark - 视图

- (void)setUI{
    [self addSubview:self.backgroundView];
    [self addSubview:self.contentView];
    [self.contentView addSubview:self.sureBtn];
}

- (void)layout{
    
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.equalTo(@0);
    }];
    
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(@0);
        make.height.equalTo(@400);
    }];
    
    [self.sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@-20);
        make.width.equalTo(@60);
        make.height.equalTo(@30);
        make.top.equalTo(@20);
    }];
    
}

#pragma mark - LazyLoad

- (UIView *)backgroundView{
    if (!_backgroundView) {
        _backgroundView = [[UIView alloc] init];
        _backgroundView.backgroundColor =[UIColor colorWithWhite:0 alpha:0.5];
    }
    return _backgroundView;
}

- (UIView *)contentView{
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = [UIColor whiteColor];
    }
    return _contentView;
}

- (UIButton *)sureBtn{
    if (!_sureBtn) {
        _sureBtn = [[UIButton alloc] init];
        [_sureBtn setTitle:@"确定" forState:(UIControlStateNormal)];
        [_sureBtn setTitleColor:UIColor.blueColor forState:(UIControlStateNormal)];
        [_sureBtn addTarget:self action:@selector(touchSureBtn) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _sureBtn;
}

#pragma mark - 交互

-(void)show
{
    UIView *view = [[UIApplication sharedApplication].keyWindow viewWithTag:12000];
    if (view) {
        [view removeFromSuperview];
    }
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.right.equalTo(@0);
    }];
    
    self.contenView.top = kScreenHeight;
    [UIView animateWithDuration:0.25 animations:^{
        self.contenView.top = kScreenHeight - 400;
        self.backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
    } completion:^(BOOL finished) {
    }];
    
}

-(void)dismiss
{
    [UIView animateWithDuration:0.25 animations:^{
        self.contenView.top = kScreenHeight;
        self.backgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}


-(void)touchSureBtn{
    [self dismiss];
    !_touchSureBtnClickBlock ? : _touchSureBtnClickBlock();
}

@end


中间弹窗

-(void)show
{
    UIView *view = [[UIApplication sharedApplication].keyWindow viewWithTag:22000];
    if (view) {
        [view removeFromSuperview];
    }
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    
    self.subView.transform = CGAffineTransformMakeScale(1.20f, 1.20f);
    
    [UIView animateWithDuration:.25 animations:^{
        self.subView.transform = CGAffineTransformMakeScale(1.0f, 1.0f);
        self.backgroundView.backgroundColor = [UIColor colorWithWhite:0 alpha:.5];
    } completion:^(BOOL finished) {
    }];
    
}

-(void)dismiss
{
    self.backgroundView.backgroundColor = [UIColor colorWithWhite:1 alpha:0];
    
    [UIView animateWithDuration:.25 animations:^{
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}


相关文章

  • PopView

    底部弹窗 中间弹窗

  • PopWindow全屏

    计算popView宽高 PopWindow全屏

  • popViewController

    popViewController返回的时候,[self.navigationController popView...

  • TableView didSelectRowAtIndexPat

    是因为被被其他控件覆盖了。 比如说:我在cell上有一个按钮,点击之后会弹出popView,popView是一个t...

  • POPView代码分析

    TYAlertControllerDemo 1,视图展示 show if (self.superview == n...

  • Swift - QQ popView

    实现这种效果: popView是一个VC,里边搞了一个tableView ,主视图是ViewController,...

  • iOS popView菜单

    封装的一个菜单控件。喜欢的可以试一下。废话不多说,直接上代码。 FTPopOverMenu.h FTPopOver...

  • 嵌入式弹窗视图点击问题

    页面实现后开始发现popView cell点击不了,后面通过- (UIView*)hitTest:(CGPoint...

  • 自定义PopView

    阅读原文 底部弹出的PopView在实际开发中使用频率很高,今天简单实现一个组件YSBasePopView,希望对...

  • Android6.0之后的拍照+本地存储权限问题

    点击头像事件: 弹出来选择拍照还是在相册中选择: 弹出popwindow对应xml: popview.xml: 响...

网友评论

      本文标题:PopView

      本文链接:https://www.haomeiwen.com/subject/klrydktx.html