自定义View 初始化 frame 写成CGRectZero即可
- 自定义分类属性
@property(nonatomic,weak)ZJAnimationPopView *popView;
@property(nonatomic,strong)UIButton *closeButton;
- 懒加载
- (UIButton *)closeButton
{
if (!_closeButton) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[self addSubview:button];
button.frame = CGRectMake(self.width - 35*ADAPTER_WIDTH, 0, 35*ADAPTER_WIDTH, 39*ADAPTER_WIDTH);//13x13 11+13+11 16+13+10
button.imageEdgeInsets = UIEdgeInsetsMake(16*ADAPTER_WIDTH, 11*ADAPTER_WIDTH, 10*ADAPTER_WIDTH, 11*ADAPTER_WIDTH);
[button setImage:[UIImage getPNGimageInBundleWithName:@"close_white"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(clickCloseButton:) forControlEvents:UIControlEventTouchDown];
_closeButton = button;
}
return _closeButton;
}
- 初始化frame
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.frame = CGRectMake(0, 0, 302*ADAPTER_WIDTH, 259*ADAPTER_WIDTH);
self.backgroundColor = [UIColor redColor];
[self closeButton];
ZJAnimationPopView *view = [[ZJAnimationPopView alloc]initWithCustomView:self popStyle:ZJAnimationPopStyleShakeFromTop dismissStyle:ZJAnimationDismissStyleDropToBottom];
view.isClickBGDismiss = YES;
view.popBGAlpha = 0.5;
[view pop];
self.popView = view;
}
return self;
}
- 点击事件
#pragma mark - 点击事件
- (void)clickCloseButton:sender
{
[self.popView dismiss];
}
- 也可以当到当前的VC的view上 主要用于跳转
@property(nonatomic,weak)BaseVC *parentVC;
- (void)setParentVC:(BaseVC *)parentVC
{
_parentVC = parentVC;
[parentVC.view addSubview:self.popView];
}
网友评论