我如何将IBAction事件与图像相关联?

问题描述:

我有一个包含动态图像的应用程序,我想使用我的自定义动画为图像设置动画。

I have a application which contains a moving image and i want to animate the image using a my custom animation.

如何关联IBAction事件使用图像?

如何检测用户触摸图像的屏幕上的坐标?

请提供您的建议。

提前致谢,您的建议最受欢迎。

Thanks in advance and Your Suggestions are Most Welcome.

您也可以这样做:

首先定义图像所在的矩形:

first define the rect where you image will be:

touchRect=CGRectMake(screen.width/2-screen.width/8, 0, screen.width/4, screen.height/5);

然后使用touchesEnded方法,您可以定义触摸该区域时要执行的操作:

then with touchesEnded method you can define what you want to do when you touch over that zone:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

        CGPoint targetPoint = [[touches anyObject] locationInView:self];
        if (CGRectContainsPoint(touchRect,  targetPoint)){
            //YOUR CODE HERE
        }
}