gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 21:16:32 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com