iphone - 当UIButton被按住时,按预设的int值递增

标签 iphone objective-c ios

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

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

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

这适用于每个按钮(其中有四个)。

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

最佳答案

我想这会对你有帮助。

-(void)incrementValue:(id)sender {
   <Code to increment value>
}

-(void)touchesBegan:(NSSet*)touches  withEvent:(UIEvent*)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 selector:@selector(incrementValue:) repeats:YES];
    }
}

-(void)touchesEnded:(NSSet*)touches  withEvent:(UIEvent*)event {
   if (timer != nil) 
      [timer invalidate];
      timer = nil;
}

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

相关文章:

objective-c - 添加 Cocoa Touch 静态库作为子项目

ios - iPad 模态表单查看 不

ios - 尽管 block 已被复制,但 block 正在阻止释放

ios - 如何在没有 Mac 的情况下测试适用于 iPhone 的 Cordova 应用程序

iphone - xpath查询问题

iphone - 在 UIView 上透明的 GPUImage 视频

ios - Objective-C : Value of array inexplicably resets every time button is clicked

ios - 网址(字符串:) gives nil error even if the String is not nil in Swift

iphone - 禁用 UIView 的自动旋转

iphone - 无法上传由 ios5 构建的应用程序 - 与 UIRequiredDeviceCapability 问题相关