美文网首页
UIview 点击区域屏蔽

UIview 点击区域屏蔽

作者: 小小不下雨 | 来源:发表于2018-12-24 16:09 被阅读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

相关文章

网友评论

      本文标题:UIview 点击区域屏蔽

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