冰雪、豪情

文本输入时,在自定义键盘上长按删除按钮

 

上图所示,为项目设计图,即在文本框中输入序列号,右侧为删除按钮,可删除文本框中的文字。

本文记录的知识要点在于,长按删除按钮,文本框中的文字会逐个删除。

由于时间仓促,来不及详细记录过程,直接上代码:

 

由于是长按删除按钮引发的操作,操作肯定要针对按钮!

对删除按钮的操作:

  a、添加长按手势

  UILongPressGestureRecognizer *press = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(reduceText:)];

    [self.deleteButton addGestureRecognizer:press];

  b、手势出发的方法

- (void)reduceText:(UILongPressGestureRecognizer *)gesture{

    

    if (gesture.state == UIGestureRecognizerStateBegan) {

        _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(deleteText) userInfo:nil repeats:YES];

    }else if (gesture.state == UIGestureRecognizerStateEnded || gesture.state == UIGestureRecognizerStateCancelled){

        [_timer invalidate];

        _timer = nil;

    }

}

posted on 2016-09-08 18:24  冰雪、豪情  阅读(1245)  评论(0编辑  收藏  举报

导航