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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top