kas-kad / AKTagsInputView

convenient input view for tags strings
Apache License 2.0
85 stars 20 forks source link

After adding tap gesture I can not remove tags by clicking x button #7

Closed appleios closed 9 years ago

appleios commented 10 years ago
@interface AKViewController ()
{
    AKTagsInputView *_tagsInputView;
    UITapGestureRecognizer *_tapGesture;
}
@end

and implementation

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = WK_COLOR(200, 200, 200, 1);
    [self.view addSubview:[self createLabel]];
    [self.view addSubview:[self createTagsInputView]];
    [self.view addSubview:[self createButton]];
    [self.view addSubview:[self clearButton]];

    _tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionTap:)];
    [self.view addGestureRecognizer:_tapGesture];
    [_tapGesture setNumberOfTapsRequired:1];
}
- (IBAction)tapAction:(id)sender
{
    [self.tagsInputView resignFirstResponder];
}

BUG: I can not delete selected tags any more

kas-kad commented 10 years ago

Do you think we need this feature in example app?

anyway I think the solution must be like:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (<touch's location in cell's view intersect button's frame>){
        return NO;
    }
    return YES;
}

check my solution on similar situation http://stackoverflow.com/questions/23847801/how-to-handle-a-tapping-on-non-cell-area-of-uitableview/23849671#23849671

appleios commented 10 years ago

its used very often in storyboard based apps, and if each client should do

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    if (<touch's location in cell's view intersect button's frame>){
        return NO;
    }
    return YES;
}

i think its a bad way. I'm sure that changing the TextInputView's super to UITextField or UITextView and doing

- (BOOL)becomeFirstResponder
{
    [super becomeFirstResponder];
    return [[self.tagsListView textField] becomeFirstResponder];
}

-(BOOL)resignFirstResponder
{
    BOOL y = [[self.tagsListView textField] resignFirstResponder];
    [super resignFirstResponder];
    return y;
}

will fix this issue.