您如何记录触摸的持续时间并在屏幕上打印出来?
这是上面的代码:
// 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/