简体   繁体   中英

Touches - User interaction of parent and child

I have an issue regarding Touches, maybe several people have had it though.

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.

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. So you only need to enable touch event where you want to have them.

i strongly recommmend to use always UIButton like this:

- (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

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

did that answer your question ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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