UIview 点击区域屏蔽

2018-12-24  本文已影响3人  小小不下雨
@interface HomeQueryView()<UIGestureRecognizerDelegate>{
    

    UIView *_mainView;
   float _mainWidth;
    float _mainHeigth;
}
@end
@implementation HomeQueryView



- (instancetype)init{
    self = [super init];
    if (self) {
        self.alpha = 0;
        
        
        [self initView];
        
        [UIView animateWithDuration:0.3 animations:^{
            self.alpha = 1;
        } completion:^(BOOL finished) {
            if (finished) {
                
            }
        }];
        
    }
    return self;
}

- (void)initView {
  self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.4];
    UITapGestureRecognizer *hideTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideView)];
    hideTap.delegate = self;
    [self addGestureRecognizer:hideTap];

   _mainWidth =300;

    _mainHeigth = 200;
    _mainView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_3SPACE(15), (SCREEN_HEIGHT-_mainHeigth)/2, _mainWidth, _mainHeigth)];
    
    _mainView.backgroundColor = [UIColor whiteColor];
    _mainView.layer.cornerRadius = SCREEN_3SPACE(8);
    _mainView.layer.masksToBounds = YES;
    [self addSubview:_mainView];
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
 
    CGPoint touchPoint = [touch locationInView:self];
    if (CGRectContainsPoint(_mainView.frame, touchPoint)) {
        return NO;
    }
    
    return  YES;
}
@end
上一篇 下一篇

猜你喜欢

热点阅读