【问题标题】:Double click event for not editable UITextView不可编辑的 UITextView 的双击事件
【发布时间】:2012-12-24 11:45:35
【问题描述】:

我没有可编辑的 UITextView。当我双击它时,我需要为其设置背景颜色。我怎样才能做到这一点?我认为不会发生 didbeginediting 事件,因为此 UITextView 不可编辑

【问题讨论】:

    标签: iphone ios


    【解决方案1】:

    请使用Tap Gesture 来实现您的描述功能。

    • 使用下面的代码在您的 TextView 中添加点按手势

      UITapGestureRecognizer* tapGestureObj = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TapMethod:)];
      tapGestureObj.numberOfTapsRequired = 2;
      [textViewObj addGestureRecognizer:tapGestureObj];
      
    • TapMethod

      -(void)TapMethod:(UITapGestureRecognizer*)gesture
      {
         //Set your logic on double tap of TextView...
      }
      

    【讨论】:

    • 谢谢,但你的回答对我不起作用,事件 TapMethod: 没有发生
    • @revolutionkpi 你是否为 textview 设置了用户交互
    • 您可以设置 userinteraction = YES 和 editable = NO 并且如果您的文本视图的父视图是 imageview 意味着您还必须为该 imageview 设置用户交互
    【解决方案2】:

    您可以将点击手势添加到文本视图中,您只需设置 numberoftapsrequired = 2 然后在手势识别器方法中您更改 bg 颜色还设置 userInteractionEnabled = yes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多