I have a method that add button on top-left of my collection view cell, and longPress recognizer. The problem is, when i set longPressRecognizer minimumPressDuration to something like 0.0001, i cant tap a button, because, instead of tapping button activates longPressRecognizer method. Please take a look:
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[[RACObserve(self, shouldEdit) deliverOnMainThread] subscribeNext:^(id x) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
if (self.shouldEdit){
self.layout.longPressGestureRecognizer.minimumPressDuration = 0.1;
int ind = indexPath.row;
NSLog(@"1 blk called");
button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTag:indexPath.row];
[cell addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.mas_left).with.offset(0);
make.top.equalTo(cell.mas_top).with.offset(0);
make.width.height.equalTo(@(20));
}];
}
I use reactive cocoa and masonry, but this actually doesn't matter, what i want is exclude button area from area, that i can use for longGestureRecognizer
.
答案 0 :(得分:2)
self.layout.longPressGestureRecognizer.minimumPressDuration = 0.1;
你可以使用self.myview.longPressGestureRecognizer.minimumPressDuration = 0.1;并且在myview中不要在myview中放置按钮。你可以点击按钮