iOS封装时候,添加背景黑色,能点击的处理

   

给相应的viewController 添加 


 self.backgroundColor = [UIColor clearColor];

    UIControl *bg = [[UIControl alloc] initWithFrame:self.bounds];

    bg.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;

    [self addSubview:bg];

    bg.backgroundColor = RGB_COLOR(50, 50, 50, 0.35);

    [bg addTarget:self action:@selector(bgDidClicked) forControlEvents:UIControlEventTouchUpInside];


- (viod)bgDidClicked

{

[self dismiss];

}


- (void)show {

    if (self.actionSheet.superview == nil) {

        [self addActionSheet];

    }

    if ([_delegate respondsToSelector:@selector(shareActionSheetWillShow)]) {

        [_delegate shareActionSheetWillShow];

    }

    __weak typeof(self) weakSelf = self;

    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

        CGRect rect = weakSelf.actionSheet.frame;

        rect.origin.y = weakSelf.bounds.size.height - rect.size.height;

        weakSelf.actionSheet.frame = rect;

    } completion:^(BOOL finished) {

    }];

}




- (void)dismiss {

    __weak typeof(self) weakSelf = self;

    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{

        CGRect rect = weakSelf.actionSheet.frame;

        rect.origin.y = weakSelf.bounds.size.height;

        weakSelf.actionSheet.frame = rect;

    } completion:^(BOOL finished) {

        if ([weakSelf.delegate respondsToSelector:@selector(shareActionSheetDidDismissed)]) {

            [weakSelf.delegate shareActionSheetDidDismissed];

        }

        [weakSelf removeActionSheet];

        [weakSelf removeFromSuperview];

    }];

}



猜你喜欢

转载自blog.csdn.net/wenhaiwang/article/details/52397414