gpt4 book ai didi

ios - 对持续触摸采取行动,而不是仅在触摸开始时采取行动 :

转载 作者:行者123 更新时间:2023-11-29 00:36:37 25 4
gpt4 key购买 nike

我正在编写一个游戏,当用户触摸屏幕的左侧或右侧时,“持续水平”会增加。目前只有当用户第一次触摸屏幕时才会增加(我的代码在下面)。只要用户将手指放在屏幕上,我就希望应用增加。我必须做什么?

-(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.view];

if (self.x >= touchPoint.x){
self.sustain += 1;

}else if (self.x <= touchPoint.x){
self.sustain += 1;

}
}

最佳答案

increased.Currently the sustain level only increase when you first touch the screen, I want the force to be applied for as long as the user holds their finger on the screen

当用户保持手指不动时,您不会收到任何消息;您的下一条消息将是 touchesEnded。因此,您需要启动一个计时器,并在每次计时器触发时根据需要不断增加力,直到您获得touchesEnded

关于ios - 对持续触摸采取行动,而不是仅在触摸开始时采取行动 :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40453593/

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