iOS - 사용자 지정 폭탄 상자

2510 단어
구체적인 봉인 코드
#pragma mark --    
- (UIView *)popTopView {
    if (!_popTopView) {
        //        
        _popTopView = [[UIView alloc] initWithFrame:CGRectMake(0, -SCREEN_HEIGHT_NO_STATUS / 2.0f, SCREEN_WIDTH_NO_STATUS, SCREEN_HEIGHT_NO_STATUS / 2.0f)];
        _popTopView.backgroundColor = [UIColor whiteColor];

        //        
        UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 64.0f)];
        titleView.backgroundColor = MAIN_TINT_COLOR;
        [_popTopView addSubview:titleView];
        
        UILabel *topTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44.0f)];
        topTitleLabel.font = [UIFont systemFontOfSize:20.0];
        topTitleLabel.textAlignment = NSTextAlignmentCenter;
        topTitleLabel.textColor = [UIColor whiteColor];
        topTitleLabel.backgroundColor = [UIColor clearColor];
        topTitleLabel.text = @"     ";
        [titleView addSubview:topTitleLabel];
        
        
    }
    return _popTopView;
}
- (UIView *)maskView {
    if (!_maskView) {
        _maskView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _maskView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.400];
        _maskView.alpha = 0.0f;
        
        //         
        UIButton *btn = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [btn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
        [_maskView addSubview:btn];
    }
    return _maskView;
}
- (void)openPopTopViewAction{ //       
    [[UIApplication sharedApplication].keyWindow addSubview:self.maskView];
    [[UIApplication sharedApplication].keyWindow addSubview:self.popTopView];
    
    [UIView animateWithDuration:0.25 animations:^{
        self.maskView.alpha = 1.0;
        self.popTopView.transform = CGAffineTransformTranslate(self.popTopView.transform, 0, SCREEN_HEIGHT_NO_STATUS / 2.0f);
    } completion:^(BOOL finished) {
        NSLog(@"%s", __func__);
    }];
}
- (void)close {
   //         
    [UIView animateWithDuration:0.3 animations:^{
        self.maskView.alpha = 0.0;
        self.popTopView.transform = CGAffineTransformIdentity;
    }completion:^(BOOL finished) {
        [self.maskView removeFromSuperview];
        [self.popTopView removeFromSuperview];
    }];
}

구체적인 호출 방법:
직접 하단 탄창 열기 방법[self openPopTopViewAction];을 호출하거나 탄창 닫기 방법[self close];을 호출합니다

좋은 웹페이지 즐겨찾기