您的位置:首页 > 其它

解决回收键盘与cell点击事件冲突问题(思路添加手势代理)

2016-10-19 15:40 573 查看
-(void)drawCollection{
    //CollectionView
    self.flowLayout = [[UICollectionViewFlowLayout
alloc]init];
    self.flowLayout.itemSize =
CGSizeMake((SCREEN_SIZE_WIDTH-5)/2, (SCREEN_SIZE_WIDTH-5)/2*(5/4));
    self.flowLayout.minimumLineSpacing =
5;
    self.flowLayout.minimumInteritemSpacing =
5;
    self.myCollectionView = [[UICollectionView
alloc]initWithFrame:CGRectMake(0,
0, SCREEN_SIZE_WIDTH,
SCREEN_SIZE_WIDTH) collectionViewLayout:self.flowLayout];
    self.myCollectionView.delegate =
self;
    self.myCollectionView.dataSource =
self;
    self.myCollectionView.backgroundColor =
NORMAL_BKG_GREY;
    [self.view
addSubview:self.myCollectionView];
    [self.myCollectionView
mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.sortBtnBkg.mas_bottom);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
    }];
    [self.myCollectionView
registerClass:[ShopSearchResultCell
class] forCellWithReuseIdentifier:@"ShopSearchResultCell"];
    //下拉
    self.myCollectionView.mj_header = [MJRefreshNormalHeader
headerWithRefreshingTarget:self
refreshingAction:@selector(makeTheTabDown:)];
    //上拉加载
    self.myCollectionView.mj_footer = [MJRefreshAutoFooter
footerWithRefreshingTarget:self
refreshingAction:@selector(makeTheTabUp:)];
    [self
getDataFromSever];

    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer
alloc] initWithTarget:self
action:@selector(fingerTapped:)];
    tapGesture.delegate =
self;
    [self.view
addGestureRecognizer:tapGesture];
}
//解决cell点击事件与回收键盘冲突问题
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch
*)touch {
    if (touch.view !=
self.myCollectionView) {
        return
NO;
    }
    return
YES;
}

-(void)fingerTapped:(UIGestureRecognizer *)tap{
    NSLog(@"点击了");
    [self.searchTF
resignFirstResponder];
    [self.myCollectionView
endEditing:YES];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐