OGeek|极客世界-中国程序员成长平台

标题: iphone - 按住 UIButton 时,按预设的 int 值递增 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 16:06
标题: iphone - 按住 UIButton 时,按预设的 int 值递增

我正在为一位客户工作,该客户希望他的按钮 - 按下时 - 将预设值添加到文本字段中的值,但在按住相同数量的同时增加。我一直在寻找整个下午,但我找不到可靠的答案。

我正在处理他的代码,他的增量代码如下:

-(IBAction)incrementInput1id)sender{  
  inputValue1.text=[NSString stringWithFormat"%g",[[inputValue1 text] floatValue]+inc1];  
  note.text=@" ";
  [self calcValue];
}

这是针对每个按钮(其中有四个)。

非常感谢您的阅读,如果您能提供帮助,也非常感谢:-D



Best Answer-推荐答案


我想这会对你有所帮助。

-(void)incrementValueid)sender {
   <Code to increment value>
}

-(void)touchesBeganNSSet*)touches  withEventUIEvent*)event {
    NSArray *array = [touches allObjects];
    UITouch *specificTouch = [array objectAtIndex:0];
    currentTouch = [specificTouch locationInView:yourUIbuttonName];
    if (CGRectContainsPoint(yourUIbuttonName.bounds, currentTouch)) {
               timer = [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selectorselector(incrementValue repeats:YES];
    }
}

-(void)touchesEndedNSSet*)touches  withEventUIEvent*)event {
   if (timer != nil) 
      [timer invalidate];
      timer = nil;
}

关于iphone - 按住 UIButton 时,按预设的 int 值递增,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5616996/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4