You can do this task this way. When you add image add a transparent button over imageView and then from the button's action start the activity.
Code for transparent button
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
Вопрос
Hello I am trying to add a tap to start image like the one in flappy birds but I cant really find what I'm looking for on the webs so I came here. I have tried using UIImageView to do this but it doesn't work.
Does anyone know how to do this?
Решение
You can do this task this way. When you add image add a transparent button over imageView and then from the button's action start the activity.
Code for transparent button
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
Другие советы
Add a UITapGestureRecognizer to the UIImageView and set the UIImageView's userInteractionEnabled to YES.
Try this
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped)];
[imageView addGestureRecognizer:tapGesture];
[tapGesture release];
and implement this
- (void)viewTapped:(UITapGestureRecognizer *)gestureRecognizer
{
UIView *tappedView = gestureRecognizer.view;
}