2012-11-02 59 views
0

我加入用自來水手勢子視圖:iOS的主視圖是響應子視圖手勢

從UIView類(masterButton):

[self addSubview:self.button]; 

// Add gesture recognizers 
[self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]]; 

的ViewController:

masterButton * button = [[masterButton alloc] initWithFrontImage:img ];

[self.view addSubview:button];

我除去子視圖:

的UIView *按鈕= [controller.view viewWithTag:controller.tagButton]; [button removeFromSuperview];

觸發手勢觸發播放音頻文件,工作得很好,但當我刪除子視圖,我點擊子視圖相同的區域播放音頻就像子視圖那裏。如果主視圖不響應子視圖的任何手勢,如何以某種方式添加子視圖?

我生成從UIView子類的子視圖,如果我嘗試添加這樣的姿態:

[self.button addGestureRecognizer:[UITapGestureRecognizer頁頭] initWithTarget:自我行動:@selector( isTapped :)]];

它不起作用。你們誰都知道爲什麼?

我真的很感謝你的幫助。

+0

你是如何刪除子視圖。發佈代碼 –

+0

作爲代碼顯示您將gesturerecognizer添加到您的視圖中我認爲您應該將其添加到您的子視圖(按鈕)。[self.button addGestureRecognizer:.......]; [self.view add subview:self.button]; –

回答

1

添加按鈕像

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]] 

[self.button removeFromSuperview]; 
0

你加入UITapGestureRecognizer到MAINVIEW

添加UITapGestureRecognizer到self.button代替self

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]]; 
[self addSubview:self.button]; 
+0

問題不在於刪除子視圖。問題是主視圖響應輕擊手勢 – Juan

+0

我編輯了代碼.. –

0

只需添加姿態向masterButton像波紋管..

[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]]; 
相關問題