有时候在做效果的时候,今天我在做点击出现冰裂开效果的时候,需要知道点击的位置,开始网上看了一下发现有一种方法判断
- (void)viewDidLoad
{
[super viewDidLoad];
CGMutablePathRef pathRef=CGPathCreateMutable();
CGPathMoveToPoint(pathRef, NULL, 4, 4);
CGPathAddLineToPoint(pathRef, NULL, 4, 14);
CGPathAddLineToPoint(pathRef, NULL, 14, 14);
CGPathAddLineToPoint(pathRef, NULL, 14, 4);
CGPathAddLineToPoint(pathRef, NULL, 4, 4);
CGPathCloseSubpath(pathRef);
CGPoint point=CGPointMake(5, 5);
CGPoint outPoint=CGPointMake(1, 1);
if (CGPathContainsPoint(pathRef, NULL, point, NO))
{
NSLog(@"point in path!");
}
if (!CGPathContainsPoint(pathRef, NULL, outPoint, NO))
{
NSLog(@"outPoint out path!");
}
}
这个其实也是可以的,但是有一个问题 如果好几个区域,pathref如何存在数组中很麻烦 这个可以看看
http://www.dapps.net/dev/iphone/how-to-create-a-simple-magazine-app-with-core-text.html
于是我换一种方式 还是九宫格,我全部是UIVIew,这样的话我可以做的就是判断了。
判断的关键代码
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint touchPoint = [touch locationInView:self.superview];
if (!_islock) {
self.point = touchPoint;
self.num = 1;
_islock = YES;
}
if (_pointTap) {
_pointTap ();
}
}
这句话就是出现的是在父视图中的坐标。
CGPoint touchPoint = [touch locationInView:self.superview];
然后就可以进行判断和加载了。。。