我已經放置了viewcontroller的uiscrollview.Then我已經將我的大尺寸圖像設置爲imageView到uiscrollView.Then我已經設置了一些按鈕到imageView。在該imageview ,我稱之爲「showRestaurant」的一種方法。但選擇器未能調用該方法。請在此幫助我。請提前致謝。@selector不工作在imageView for UIButton與圖像
代碼:
- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer {
float newScale = [imageScrollView zoomScale] * ZOOM_STEP;
CGRect zoomRect = [self zoomRectForScale:newScale withCenter:[gestureRecognizer locationInView:gestureRecognizer.view]];
UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn1 setImage:[UIImage imageNamed:@"restaurant.png"] forState:UIControlStateNormal];
UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
[btn2 setImage:[UIImage imageNamed:@"restaurant.png"] forState:UIControlStateNormal];
[imageScrollView zoomToRect:zoomRect animated:YES];
if(newScale==1.500){
btn1.frame = CGRectMake(2370.828125,1020.015625,35,34);
[btn1 addTarget:self action:@selector(showRestaurant) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn1];
btn2.frame = CGRectMake(2270.828125,1070.015625,35,34);
[btn2 addTarget:self action:@selector(showRestaurant) forControlEvents:UIControlEventTouchUpInside];
[imageView addSubview:btn2];
}
}
-(void)showRestaurant{
NSLog(@"testing321");
}
我已經編輯了code.Now告訴我answer.What我必須要在選擇器中調用方法嗎? – vinay 2010-08-09 11:49:01
那麼,按鈕出現?如果不是,則不輸入「如果」。如果是,並且觸摸按鈕不會帶來「testing321」消息,那麼設置UIScrollView可能會有問題(如http://stackoverflow.com/questions/650437/iphone-uiscrollview-with-uibuttons - 如何對重新創建-跳板)。所以它可能有助於發佈您用於設置「imageScrollView」變量的代碼。 – DarkDust 2010-08-09 12:13:53