简体   繁体   English

触摸-父母与孩子的用户互动

[英]Touches - User interaction of parent and child

I have an issue regarding Touches, maybe several people have had it though. 我有一个关于Touches的问题,也许有几个人遇到过。

I have a view that has some Labels and imageviews on it. 我有一个上面有一些标签和图像视图的视图。 If i disabled the touches of my View by saying userinteraction disabled then all the touches of all subviews get disabled, what if i may want to have touches enabled for a few and disabled for a few, when userinteraction of view is disabled. 如果我通过说禁用userinteraction来禁用View的触摸,那么所有子视图的所有触摸都会被禁用,而当禁用userview的视图时,如果我希望启用触摸并禁用一些触摸该怎么办。

Is this the only solution: Create two seperate views, out of which one's user interaction would be enabled and others' would be disabled and implement my stuff on top of it? 这是唯一的解决方案:创建两个单独的视图,从中启用一个用户交互,而另一个视图则被禁用,并在此之上实现我的东西吗?

Regards, Reno Jones 问候,里诺·琼斯

Usually UILabel and UIImageView don't have touch event by default. 通常,默认情况下,UILabel和UIImageView没有触摸事件。 So you only need to enable touch event where you want to have them. 因此,您只需要在想要的地方启用触摸事件即可。

i strongly recommmend to use always UIButton like this: 我强烈建议始终使用如下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");
}

and avoid subclassing UIView just to implement 避免子类化UIView只是为了实现

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

did that answer your question ? 那回答了你的问题吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM