解決回收鍵盤與cell點選事件衝突問題(思路新增手勢代理)
-(void)drawCollection{
//CollectionView
self.flowLayout = [[UICollectionViewFlowLayoutalloc]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 = [[
self.myCollectionView.delegate = self;
self.myCollectionView.dataSource = self;
self.myCollectionView.backgroundColor = NORMAL_BKG_GREY;
[self.viewaddSubview:self.myCollectionView
[self.myCollectionViewmas_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.myCollectionViewregisterClass:[ShopSearchResultCell
//下拉
self.myCollectionView.mj_header = [MJRefreshNormalHeaderheaderWithRefreshingTarget:selfrefreshingAction:@selector(makeTheTabDown:)];
//上拉載入
self.myCollectionView.mj_footer = [MJRefreshAutoFooterfooterWithRefreshingTarget:selfrefreshingAction:@selector(makeTheTabUp:)];
[selfgetDataFromSever];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(fingerTapped:)];
tapGesture.delegate = self;
[self.viewaddGestureRecognizer:tapGesture];
}
//解決cell點選事件與回收鍵盤衝突問題
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
if (touch.view != self.myCollectionView) {
returnNO;
}
returnYES;
}
-(void)fingerTapped:(UIGestureRecognizer *)tap{
NSLog(@"點選了");
[self.searchTFresignFirstResponder];
[self.myCollectionViewendEditing:YES];
}