嘿,
当我在目标 c 中触摸它时如何制作改变颜色的东西,我希望整个屏幕都是可触摸的,并想用手指在上面画东西。我触摸的所有地方都应该改变颜色。最好的方法是什么?我已经实现了touchesMoved来获取触摸的坐标。
UITouch * touch = [touches anyObject]; CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
任何示例代码都会很好,谢谢。
先感谢您,
我有以下代码,但它不会打印我触摸的任何内容
-(void)setPaths:(NSMutableArray *)paths
{
self.paths =[[NSMutableArray alloc]init];
}
-(void)setAPath:(UIBezierPath *)aPath
{
self.aPath=[UIBezierPath bezierPath];
}
-(void) drawRect:(CGRect)rect{
[super drawRect:rect];
[[UIColor blackColor] set];
for (UIBezierPath *path in paths) {
[path stroke];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.paths addObject:self.aPath];
//self.aPath=[UIBezierPath bezierPath];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow];
[self.aPath addLineToPoint:[touch locationInView:self]];
// [self.aPath addLineToPoint:[touch locationInView:touch]];
NSLog(@"Position of touch: %.3f, %.3f", pos.x, pos.y);
}
@end