HY,觸摸客觀畫的東西ç
如何讓東西時,我的目標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
不工作:S,去看教程 –