![](/img/trans.png)
[英]How implement longPressGestureRecognizer for subview with disabled user interaction?
[英]User Interaction disabled in subview of a subview
我將一組視圖添加到主視圖中,如下所示。我有一個視圖,其中包含一組子視圖(標簽,按鈕等)。然后將此視圖添加到主視圖中。 我的ptoblem就是當我點擊View中的Button時,它的IBAction
沒有被調用。 我的問題是如何在mainView的子視圖中調用Button tap動作?
for (int i = 0;i < controls.count;i++) {
UIView *view = [[UIView alloc]init];
view.userInteractionEnabled = YES;
for (int j=0; j<viewsArray.count; j++) {
UIView *subView = viewsArray[i]; // this may be Button, Label etc
subView.tag = controlCount++;
[view addSubview:subView];
}
[self.mainView addSubview:view];
}
問題是沒有設置UIView(變量view
)框架(它是0,0,0,0)。
改成:
UIView *view = [[UIView alloc]initWithFrame:<a frame>];
例如, <a frame>
可以是CGRectMake(0, 0, 50, 50)
。
該視圖的子視圖也應該具有框架集。 請記住,視圖( subview
)框架是指其父視圖中的框架(在您的案例view
)
你可以刪除view.userInteractionEnabled = YES;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.