刚开始 iOS 编程,试图让 UITapGestureRecognizer 使用 iOS 5.1 模拟器工作,我在点击时似乎无法获得正确的值。这是我从 nathan eror 对nathan eror的How to add a touch event to a UIView?的回答中获取的代码。
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:[recognizer.view superview]];
NSLog(@"touched points: %g, %g", location.x, location.y);
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor blackColor];
NSLog(@"gets in here");
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleFingerTap];
}
每次我在模拟器上点击我的 macbook pro 上的触控板时,我的值都会得到 0.000000。是因为模拟器吗?还是我做错了什么?
PS有谁知道如何在发布这个问题时将代码突出显示为objective-C?提前谢谢