你好,我想在 iOS 的 UITouch
中围绕一个点画一个圆圈。我也想画在该点相交的十字线,但我还没有走那么远。这应该能够在最多 10 个接触点发生,这就是为什么您会在开头看到 for 循环的原因。任何帮助将非常感激。
我在全局变量中列出了点,因为我在 touchesBegan
、touchesMoved
和 touchesEnded
中使用了它。我需要显示形状,直到启动新的触摸点。我对这一切还很陌生,有点不知所措。
谢谢你的时间。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
radius = 10;
CGContextRef context = UIGraphicsGetCurrentContext();
for (UITouch *touch in touches)
{
point = [touch locationInView:self.view];
CGContextSetRGBStrokeColor(context, 255.0, 255.0, 0.0, 1.0);
CGContextAddArc(context, point.x, point.y, radius, 0, M_PI*2, YES);
CGContextStrokePath(context);
NSLog(@"X: %.3f Y: %.3f Began", point.x, point.y);
}
self.timestampstart = [NSDate date];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
self.timestampend = [NSDate date];
self.duration.text = [[NSString alloc] initWithFormat:@"%.3f s", [self.timestampend timeIntervalSinceDate:self.timestampstart]];
NSLog(@"X: %.3f Y: %.3f Ended. Duration %.3f", point.x, point.y, [self.timestampend timeIntervalSinceDate:self.timestampstart]);
}
最佳答案
我认为问题在于您不能在此方法中使用 Core Graphics。通常,UIView
的drawRect
方法是您要使用它的地方。
也许使用 UITapGestureRecognizer
添加自定义 UIView
子类(代表您的圈子)会更好?因此,您非常关心它所属的位置:什么当有人点击 View 时应该发生什么,您绘制的对象应该是什么样子。两个问题,很好地分开了。 (关注点分离是或者至少将是你的 friend ,相信我。)
关于ios - 我的形状不会出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27626830/