2012-09-10 55 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 –