我如何将IBAction事件与图像相关联? [英] How can i associate an IBAction event with an image?

查看:68
本文介绍了我如何将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
        }
}

这篇关于我如何将IBAction事件与图像相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆