新的iPhone開發。我有一個視圖,它包含一個包含UIImageView的UIScrollView。我在圖像視圖中添加了一個(雙)輕擊手勢識別器,這會使警告框打開。出於某種原因,我確信我只是被推遲了,它打開了3次。使用UITapGestureRecognizer
這裏是我的代碼:
- (void)viewDidLoad {
scrollView.delegate = self;
UIImage* image = imageView.image;
imageView.bounds = CGRectMake(0, 0, image.size.width, image.size.height);
scrollView.contentSize = image.size;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
tapGesture.numberOfTapsRequired = 2;
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
NSLog(@"LOADED");
[super viewDidLoad];
}
-(IBAction) handleTapGesture:(UIGestureRecognizer *) sender {
CGPoint tapPoint = [sender locationInView:imageView];
int tapX = (int) tapPoint.x;
int tapY = (int) tapPoint.y;
NSLog(@"TAPPED X:%d Y:%d", tapX, tapY);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"How are you?" delegate:nil cancelButtonTitle:@"I'm awesome." otherButtonTitles:nil];
[alert show];
[alert release];
}
我剛開始iPhone開發幾天前。這個問題讓我想起了我在javascript中處理過的事件冒泡問題。有任何想法嗎?
哦,好像這是值得注意的是,NSLog的不發生的所有三次。 – tybro0103 2010-10-22 22:14:35