iphone - 记录触摸的持续时间,然后打印

标签 iphone xcode

如何记录触摸的持续时间并在屏幕上打印出来?

enter image description here

上面的代码是这样的:

// add this ivar to your view controller
NSTimeInterval lastTouch;
int textTime;

// assign the time interval in touchesBegan:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
{
    lastTouch = [event timestamp];
}


// calculate and print interval in touchesEnded:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
{
    NSTimeInterval touchBeginEndInterval = [event timestamp] - lastTouch;
    textTime = touchBeginEndInterval;
    NSLog(@"touchBeginEndInterval %f", touchBeginEndInterval);
    dynLabel.text = textTime;
}

最佳答案

dynLabel.text = textTime;

标签的 text 属性需要一个 NSString*,但你给它一个 NSTimeInterval 即一个号码。这就是错误的含义。使用例如创建一个字符串NSString 的 -stringWithFormat: 方法。

关于iphone - 记录触摸的持续时间,然后打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12737250/

相关文章:

iphone - 标签栏 Controller :shouldSelectViewController method doesn't fire

iphone - xcode中的文件夹结构与finder中的文件夹结构

ios - Swift 2/XCode 7 - 在另一个类中调用 "EXC_BAD_ACCESS (code=2...)"时为 "ViewController().view"

ios - Xcode 9.2 说我的 "iPhone has recently restarted"并且不会运行

jquery - iPhone 上的 Fancybox 问题

iphone - Bonjour 联网(发送消息)到两个以上的 iOS 设备

ios - 如何在 ios swift 中部分更改背景 View 颜色

ios - Swift:如何将 wilDisplayCell 分配给特定的自定义寄存器单元?

iphone - GLfloat 动态数组声明

iphone - ASIHTTPRequest 假人