用Quartz 2d勾画图形可能大家都会,但是如何让我们勾画的图形响应事件呢?有人会说用坐标计算啊,但是有时候对不规则的图形,这个办法不使最简单的做法,下面的代码可以帮你很容易实现这一点。
//只是代码而已 , 如果有兴趣的同学 我们可以私下探讨 email:zhuolaiqiang@mail.com
//原帖地址 http://blog.csdn.net/diyagoanyhacker/article/details/6608840
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
// Depending on your code, you may need to check a different view than self.view
// You should probably check the docs for the arguments of this function--
// It's been a while since I last used it
if (CGPathContainsPoint(yourCircle, nil, location, nil)) {
// Do something swanky
} else {
// Don't do teh swank
}
}
如何使drawrect:画出的图形响应事件 Quartz 2d 事件 touch
最新推荐文章于 2023-01-09 10:27:20 发布