我有一个小的(30X30 大小)UIView 网格,我通过使用以下代码在屏幕上点击两个点作为起点和终点在它们上面画一条线:
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGFloat components[] = {244.0f/255.0f, 226.0f/255.0f, 119.0f/255.0f, 0.8};
CGColorRef color = CGColorCreate(colorspace, components);
CGContextSetStrokeColorWithColor(context, color);
CGContextSetLineWidth(context, 20.0);
CGContextMoveToPoint(context, startPoint.x, startPoint.y);
CGContextAddLineToPoint(context, endPoint.x, endPoint.y);
CGContextStrokePath(context);
CGColorSpaceRelease(colorspace);
CGColorRelease(color);
点击屏幕上的两个点并绘制一条线可以正常工作,但我如何让所有 View 都与线相交? 我想在 touches end 方法中获得这些 View 。
- (void) touchesEndedNSSet *)touches withEventUIEvent *)event {
CGPoint pt = [[touches anyObject] locationInView:alphabetView];
UIView *touched = [alphabetView hitTest:pt withEvent:event];
CGPoint p = touched.center;
// code here to get view list.
}
任何帮助将不胜感激。
如果满足以下条件,一条线段(从 A 点到 B 点)与一个矩形( View 框架)相交:
如果 (1) 和 (2) 的答案都是 NO,则线段不与 矩形。
函数 checkLineIntersection
来自 this answer可能
有助于检查条件 (1)。
CGRectContainsPoint()
可用于检查条件(2)。
关于ios - 获取与线IOS相交的所有 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16052696/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |