我有一个双应用程序,并将 touchesBegan 的代码块从 iPhone 代码复制到 iPad。我没有进行任何更改,并且该方法总是在第一次触摸时为 x 和 y 给我一个零。
代码块:
-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event {
int iCardId;
NSSet *allTouches = [event allTouches];
// we are dealing with one finger get first touch
// get first touch
UITouch *touch=[[allTouches allObjects] objectAtIndex:0];
// get the x and y
CGPoint pt = [touch locationInView: self.view];
float x=pt.x; // this is always a zero
float y=pt.y; // this is always a zero
.........
.........
.........
}