1
所以我有一個UIView,我稱之爲ctrView和這個ctrView被添加到我的UIViewController的視圖。它基本上只是一個較小的矩形框架。我在這個容器視圖的右上角添加了一個UIButton,但是看起來當點擊位於ctrView之外的UIButton區域時不會觸發與按鈕相關的操作。只有容器視圖內的UIButton區域觸發該操作。我該如何解決這個奇怪的問題?UIButton tapable區域以外的子視圖
UIButton *closeButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[closeButton setImage:[UIImage imageNamed:@"close.png"] forState:UIControlStateNormal];
[closeButton setBackgroundColor:[UIColor clearColor]];
[closeButton addTarget:self action:@selector(closeZoomedImageView) forControlEvents:UIControlEventTouchUpInside];
[closeButton setCenter:CGPointMake(ctrView.frameX + ctrView.frameWidth - 30, ctrView.frameY - 15)];
[ctrView addSubview:closeButton];
[closeButton release];
其他文字拉出關閉按鈕主視圖而不是容器? – adit
是的,拉起關閉按鈕到一個更大的視圖,沒有背景顏色,對於用戶來說,這不會改變外觀,因爲你的按鈕現在會收到觸摸事件 –
你是對的親愛的!爲了更好地理解這個beahaviour,請參閱http://developer.apple.com/library/ios/#documentation/uikit/reference/UIControl_Class/Reference/Reference.html –