2012-09-10 2 views
-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)]; 
} 

답변

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

+0

UIViewImage 코드를 작성 미안 아차 – Aptlymade

+0

존재 서둘러이었다하지 않습니다 내가 지금 변경 문제가 어떤 야해 있도록 더보기 : D –

관련 문제