【问题标题】:Swipe left gestures over UITextField在 UITextField 上向左滑动手势
【发布时间】:2013-10-01 17:14:20
【问题描述】:

我在 tableviewcells 中有 UITextFields。当您在不属于文本字段的单元格上滑动时,删除操作会按预期出现。如果您在文本字段上滑动,它会阻止弹出删除。

如何解决此问题,以便您可以在输入上滑动并且单元格将触发删除操作?

【问题讨论】:

  • 这个问题你解决了吗?
  • 不。我围绕这个问题重新设计了界面。
  • 尝试添加 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath。它的作用在于魅力

标签: ios objective-c uitableview tableview


【解决方案1】:

听起来你需要设置cancelsTouchesInView 属性

yourGestureRecognizer.cancelsTouchesInView = NO;

【讨论】:

    【解决方案2】:

    我认为这里的问题是文本字段上的触摸干扰了您的滑动手势识别器(可能附加到父视图)。我在放置在 UIScrollView 中的文本字段时遇到了类似的问题。

    我通过在我的 UITextField 上覆盖一个清晰的 UIView 来解决这个问题。然后,我为这个清晰的视图分配了一个 UITapGestureRecognizer,以在用户点击该字段时将文本字段设置为第一响应者。否则,刷卡被发送到父视图(滚动视图),它可以毫无问题地识别刷卡。这有点蹩脚,但它的工作原理。

    这种情况与您的情况有些不同,但我认为这是同一个问题。这是我的代码的样子,希望对您有所帮助:

    // UIView subclass header
    @interface LSAddPageView : UIView
    
    @property (weak, nonatomic) IBOutlet UITextField *textField;  // Connected to the UITextField in question
    @property (strong, nonatomic) UIView *textFieldMask;
    @property (assign, nonatomic) BOOL textFieldMaskEnabled;
    
    @end
    
    // UIView subclass implementation
    @implementation LSAddPageView
    
    - (void)awakeFromNib
    {
        [super awakeFromNib];
    
        _textFieldMask = [UIView new];
        _textFieldMask.backgroundColor = [UIColor clearColor];
        [self insertSubview:_textFieldMask aboveSubview:self.textField];
    }
    
    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        _textFieldMask.frame = self.textField.frame;
    }
    
    - (BOOL)textFieldMaskEnabled
    {
        return _textFieldMask.hidden == NO;
    }
    
    - (void)setTextFieldMaskEnabled:(BOOL)textFieldMaskEnabled
    {
        _textFieldMask.hidden = !textFieldMaskEnabled;
    }
    
    @end
    

    然后在控制器中:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        _addPageView = (LSAddPageView*)self.view;
    
        _maskGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMask:)];
        _maskGestureRecognizer.numberOfTapsRequired = 1;
        _maskGestureRecognizer.numberOfTouchesRequired = 1;
        [_addPageView.textFieldMask addGestureRecognizer:_maskGestureRecognizer];
    
        self.textField.delegate = self; // Set delegate to be notified when text field resigns first responder
    }
    
    - (void)didTapMask:(UIGestureRecognizer*)recognizer
    {
        _addPageView.textFieldMaskEnabled = NO;
        [self.textField becomeFirstResponder];
    }
    
    - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
    {
        _addPageView.textFieldMaskEnabled = YES;
        return YES;
    }
    

    【讨论】:

      【解决方案3】:

      来自UIButton & UITextField will block UITableViewCell being swipe to delete

      self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;
      

      这将使文本字段不会停止向左滑动提示

      【讨论】:

        猜你喜欢
        • 2015-07-10
        • 2011-07-23
        • 1970-01-01
        • 1970-01-01
        • 2020-11-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多