不要爲您的手勢識別器創建新視圖。識別器實現了一個locationInView:方法。爲包含敏感區域的視圖進行設置。在handleGesture上,點擊測試你關心的區域,如下所示:
0)在包含您關心的區域的視圖上執行所有操作。不要僅爲手勢識別器添加特殊視圖。
1)安裝mySensitiveRect
@property (assign, nonatomic) CGRect mySensitiveRect;
@synthesize mySensitiveRect=_mySensitiveRect;
self.mySensitiveRect = CGRectMake(0.0, 240.0, 320.0, 240.0);
2)創建gestureRecognizer:
gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
[self.view addGestureRecognizer:gr];
// if not using ARC, you should [gr release];
// mySensitiveRect coords are in the coordinate system of self.view
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
CGPoint p = [gestureRecognizer locationInView:self.view];
if (CGRectContainsPoint(mySensitiveRect, p)) {
NSLog(@"got a tap in the region i care about");
} else {
NSLog(@"got a tap, but not where i need it");
}
}
敏感RECT應該在MyView的座標系統進行初始化,同樣的看法,對此你附加的識別。
對不起,這會怎麼做?併爲mySensitiveRect變量,我使用(0,0,320,480)?你有完整的例子嗎?感謝:D – 2012-02-19 12:18:13
@DavidMurray:希望這更清晰 – danh 2012-02-19 18:37:17
謝謝,這使它。 :-) – 2012-02-20 13:04:34