例如:
我用手指在下面画橙色线,因为它触摸了蓝色方块,它们变亮了。
我可以从我发现的StackOverflow问题/教程中使用UIBezierPath来画一条线,但我不知道如何使其消失或与其他视图交互。
这不是游戏,而是常规的iOS应用。我不确定这是否会改变事情。
有任何想法吗?
我实现了一个不平滑的垃圾版本,但是具有我想要的线条图感觉
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[[event allTouches] allObjects] firstObject];
CGPoint point = [touch locationInView:self.view];
UIView *dot = [[UIView alloc] initWithFrame:CGRectMake(point.x, point.y, 6, 6)];
dot.backgroundColor = UIColorFromRGB(0xeb3b6e);
dot.layer.cornerRadius = 3;
for(UILabel *el in self.testLabels){
CGPoint pointInSuperView = [self.view convertPoint:point toView:el.superview];
if(CGRectContainsPoint(el.frame, pointInSuperView))
el.textColor = UIColorFromRGB(0xeb3b6e);
}
[self.view addSubview:dot];
[UIView animateWithDuration:1.0 animations:^{
dot.alpha = 0;
} completion:^(BOOL finished) {
[dot removeFromSuperview];
}];
}
最佳答案
如果用“它”中的“它接触到蓝色方块”,则表示该行,这将很难做到。直线没有矩形,因此您不能使用CGRectIntersectsRect之类的方法来查看直线和正方形是否相交。使用手指的触摸点(无论如何都应该是线条)会容易得多。您可能希望在数组中有蓝色方块,并在touchesMoved内部循环遍历数组以查看是否有任何方块包含接触点(使用CGRectContainsPoint)。