2010-09-22 139 views
0

是否有任何方法來隱藏UIButton,直到UIImageView被按下? 當圖片被按下時,我需要顯示後面的按鈕,就像它在iPhone上的照片應用程序工作? 這裏是我的UIButton的代碼:當圖像被觸摸時顯示UIButton?

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self ladeImage]; 
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    btn.frame = CGRectMake(10, 10, 40, 40); 
    [btn addTarget:self action:@selector(goToViewA) forControlEvents:UIControlEventTouchUpInside]; 
    [btn setTitle:@"<<" forState:UIControlStateNormal]; 
    [self.view addSubview:btn]; 

    } 
+0

有沒有辦法讓你接受更多的答案,你所問的24個問題? – willcodejavaforfood 2010-09-22 08:10:00

+0

你的問題是什麼?對不起,我不明白你的意思 – Marco 2010-09-22 08:14:02

+0

有一個選項,在網站上說如果答案是好的或不。而且你沒有接受任何關於你所有問題的答案。所以,也許你可以從這一步開始 – Vinzius 2010-09-22 08:20:12

回答

2

第一步:btn.hidden = YES

然後,你必須子類的UIImageView作出反應,其touchesEnded:事件並更改按鈕的隱藏屬性出現。爲此,正確的方法是創建一個協議(使用viewTouched方法)。在包含按鈕和ImageView的viewController中實現該協議。向子類ImageView添加一個委託(即id<MyCustomProtocol> _delagate;),並將視圖控制器分配給這個操作。

+0

好吧,我現在已經解決了這個問題,非常感謝你,我也接受了答案:-) – Marco 2010-09-22 08:57:39

0
btn.hidden = YES; 

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image name"]]; 
imageView.userInteractionEnabled = YES; // here to enable touch event 
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGestureRecongizer:)]; // handleTapGestureRecongizer is method will call when tap even fire 
[imageView addGestureRecognizer:tap]; // Add Tap gesture recognizer to image view 
[tap release], tap = nil; 
[self.view addSubview:imageView]; 
[imageView release], imageView = nil; 

方法handlerTapGestureRecognizer:

- (void)handleTapGestureRecongizer:(UITapGestureRecognizer *)gestureRecognizer{ 
if (gestureRecognizer.state == UIGestureRecognizerStateEnded) { 
    btn.hidden = NO; 
} 

}

有樂趣!