开发者

Button click not working when in presence of single Tap gesture

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜