Pregunta

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?

¿Fue útil?

Solución

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]; 

Otros consejos

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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top