-1

基本上触摸屏图像应该出现在触摸但不起作用的地方。

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location = [touch locationInView:touch.view];
    UIImage *image = [[UIImage alloc]initWithContentsOfFile:@"BluePin.png"];
    [image drawAtPoint:CGPointMake(location.x, location.y)];
}
4

1 回答 1

0

您不能调用 UIImage ,因为它只保存图像数据,您必须改用 UIImageView ,然后它应该可以工作。

所以改用这个:

-(void) touchBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
UImageView *imageView = [[UIImageView alloc] init];
UIImage *image = [[UIImage imageNamed:@"BluePin.png"];
imageView.image = image;
[imageView drawAtPoint:CGPointMake(location.x, location.y)];
}

希望这会有所帮助:D

于 2012-09-10T21:43:28.373 回答