开发者

Button click not working when in presence of single Tap gesture

开发者 https://www.devze.com 2023-04-13 03:22 出处:网络
I have view hierarchy as follows MyViewController --> ScrollView(added via IB) --> ImageView (+ zooming there) ---> button added on image View(added via code)

I have view hierarchy as follows

MyViewController --> ScrollView(added via IB) --> ImageView (+ zooming there) ---> button added on image View(added via code)

imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];
[scroll addSubview:imageView];

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

myButton.frame = CGRectMake(660, 120, 40, 40);

[my开发者_如何学JAVAButton setTitle:@"10" forState:UIControlStateNormal];

[myButton addTarget:self action:@selector(asiaPressed:) forControlEvents:UIControlEventTouchUpInside];

[myButton setEnabled:YES];
[imageView addSubview:myButton];

later on in view controller, i defined selector as

-(void) asiaPressed:(id)sender{
NSLog(@"asiaPressed clicked");

}

But it is never going inside selector..

Pls help...i guess it is very basic error..

Thanks in advance


UIImageView has userInteractionEnabled property set to NO by default so it (and its subviews) does not receive touch events. You need to set that property to YES manually:

...
imageView.userInteractionEnabled = YES;
...

P.S. You also mention gesture recognizer in question title, however have not posted any code with it - so if it present it may also cause the problems, but the problem is most likely is what I described above

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号