iPhone问题的多重接触
我如何才能做到,当用户在操纵杆上玩游戏以移动中间的角色时,他们也可以触摸屏幕右下角(第二次触摸)来开火?我看了其他的问题,但我还是不明白 这基本上就是代码iPhone问题的多重接触,iphone,objective-c,touchesbegan,Iphone,Objective C,Touchesbegan,我如何才能做到,当用户在操纵杆上玩游戏以移动中间的角色时,他们也可以触摸屏幕右下角(第二次触摸)来开火?我看了其他的问题,但我还是不明白 这基本上就是代码 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //make the touch point... UITouch *touch = [[event allTouches]anyObject]; CGPoint point = [touch locati
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
//make the touch point...
UITouch *touch = [[event allTouches]anyObject];
CGPoint point = [touch locationInView:touch.view];
if (//touching a certain area (on the joystick)) {
//do stuff
}
else if (point.x > 300 && point.y > 200) {
/fire method
}
}
那么基本上我如何调用touches再次开始查找CGPoint的位置,并确定是否应该调用fire方法
谢谢
编辑:
我尝试了第二种选择,并做到了:
在view controller.h中,我添加了:
@interface fireView: UIView
@end
在.m中,我补充道:
@implementation fireView -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"hi");
}
@end
…但它不记录/打印“hi”?使用2。您可以创建两个所需大小的不可见视图-一个用于操纵杆,另一个用于消防按钮。对于每个视图,使用单个手势识别器。然后你就可以用不同的方法来处理这些视图上的点击,而不必检查它是火还是操纵杆
假设您已经有了两个视图-joystickView和fireView。那就这样做吧
UITapGestureRecognizer* fireTapGestureRec= [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(fireTapped:)];
fireTapGestureRec.delegate = self;
fireTapGestureRec.numberOfTapsRequired = 1;
fireTapGestureRec.numberOfTouchesRequired = 1;
[fireView addGestureRecognizer:fireTapGestureRec];
[fireTapGestureRec release];
并编写firetaped:
来处理事件。操纵杆也是一样
编辑
第二种选择(在评论中建议)
创建UIView的子类,如
@interface fireView: UIView
@interface joystickView: UIView
对于每个子类,编写自己的
touchesestart:
或touchesend:
对于游戏,UIgestureRecognitor引入的延迟确实令人烦恼。我会建议你的方法,但要对两个UIView进行子类化并使用touchesBeganHello,嗯,我已经尝试了第二个选项并做到了:在视图控制器中。我添加了:(at)接口fireView:UIView(at)end和in.m我添加了:(at)实现fireView-(void)touchesbeated:(NSSet*)toucheevent:(UIEvent*)事件{NSLog(@“hihihi”);}(at)结束,但它不记录“hihihi”?你能发布代码,将fireView添加到游戏的主视图中,以及你认为对问题有用的所有内容,作为编辑吗?