gpt4 book ai didi

ios - Sprite Kit检测触摸位置

转载 作者:可可西里 更新时间:2023-11-01 05:12:44 25 4
gpt4 key购买 nike

我想根据您触摸屏幕的左半部分或右半部分来运行不同的操作。所以当你触摸左半边时一个 Action ,当你触摸右半边时另一个 Action 。

我想我可以制作一个覆盖一半屏幕的透明按钮图像并使用 this code触摸时运行一个 Action ,但我不认为这是要走的路。有没有更好的方法来检测触摸的位置?

最佳答案

覆盖 touchesEnded:withEventtouchesBegan:withEvent: 方法来执行此操作:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];

if(touch){
if([touch locationInView:self.view]>self.size.width/2){
[self runTouchOnRightSideAction];
}else{
[self runTouchOnLeftSideAction];
}
}
}

关于ios - Sprite Kit检测触摸位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21738716/

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