簡體   English   中英

觸摸-父母與孩子的用戶互動

[英]Touches - User interaction of parent and child

我有一個關於Touches的問題,也許有幾個人遇到過。

我有一個上面有一些標簽和圖像視圖的視圖。 如果我通過說禁用userinteraction來禁用View的觸摸,那么所有子視圖的所有觸摸都會被禁用,而當禁用userview的視圖時,如果我希望啟用觸摸並禁用一些觸摸該怎么辦。

這是唯一的解決方案:創建兩個單獨的視圖,從中啟用一個用戶交互,而另一個視圖則被禁用,並在此之上實現我的東西嗎?

問候,里諾·瓊斯

通常,默認情況下,UILabel和UIImageView沒有觸摸事件。 因此,您只需要在想要的地方啟用觸摸事件即可。

我強烈建議始終使用如下UIButton:

- (void)viewDidLoad {
    UIButton *buttonActionA = [[UIButton alloc] initWithFrame:CGRectMake(50.0, 50.0, 100.0, 100.0)];
    [buttonActionA addTarget:self action:@selector(doActionA) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonActionA];
    [buttonActionA release];
}

- (void) doActionA {
    NSLog(@"This is Action A");
}

避免子類化UIView只是為了實現

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

那回答了你的問題嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM