2014-05-22 76 views
0
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
UITouch *touch = [[event allTouches] anyObject]; 
CGPoint endlocation = [touch locationInView:touch.view]; 
UIImage* thing; 
UIImageView* thing2 = [[UIImageView alloc] init]; 
UIImageView* thing3=[[UIImageView alloc] init]; 
switch ([_diagramselect selectedSegmentIndex]) { 
    case 0: 
     thing = [UIImage imageNamed:@"makeO"]; 
     [thing2 setFrame:CGRectMake(endlocation.x-72,endlocation.y-172,25,25)]; 
     [thing2 setImage:thing]; 
     [_field addSubview:thing2]; 
     break; 
    case 1: 
     thing = [UIImage imageNamed:@"missX"]; 
     [thing2 setFrame:CGRectMake(endlocation.x-72,endlocation.y-172,25,25)]; 
     [thing2 setImage:thing]; 
     [_field addSubview:thing2]; 
     break; 
    case 2: 
     CGContextRef *context = UIGraphicsGetCurrentContext(); 
     CGContextSetStrokeColor(context,black); 
     CGContextBeginPath(context); 
     CGContextMoveToPoint(context,startlocation.x,startlocation.y); 
     CGContextAddLineToPoint(context,endlocation.x,endlocation.y); 
     CGContextStrokePath(context); 





     /*thing = [UIImage imageNamed:@"passArrow"]; 
     [thing3 setFrame:CGRectMake(startlocation.x-72,startlocation.y-172,endlocation.x-startlocation.x,endlocation.y-startlocation.y)]; 
     [thing3 setImage:thing]; 
     [_field addSubview:thing3]; 
     */ 

     break; 
    case 3: 
     thing = [UIImage imageNamed:@"trussArrow"]; 
     break; 

    default: 
     break; 
} 

情況2旨在從水龍頭的初始位置到水龍頭的結束位置。但是下面的代碼在CGContextRef行上給出了「預期表達式」的錯誤,結果下面的行不能識別上下文。這裏有什麼問題?有沒有一個特定的觀點,這個代碼需要針對,如果是的話,我會如何做到這一點?謝謝!如何將CGContext實現爲實際代碼?

+0

此代碼不起作用,因爲沒有當前上下文。如何繪製:http://www.apeth.com/iOSBook/ch15.html – matt

回答

1

嘗試沒有指針引用星號:

CGContextRef context = UIGraphicsGetCurrentContext(); 
CGContextSetStrokeColor(context,black); 
CGContextBeginPath(context); 
CGContextMoveToPoint(context,startlocation.x,startlocation.y); 
CGContextAddLineToPoint(context,endlocation.x,endlocation.y); 
CGContextStrokePath(context); 

此外,你可能想看看這取決於你想做什麼UIGraphicsBeginImageContext()UIGraphicsEndImageContext()

+0

你能推薦一個很好的教程嗎? – vacioarconte

+0

http://www.raywenderlich.com/或http://teamtreehouse.com – brandonscript

+0

Err,wha?你的意思是蘋果喜歡typedef'ing參考類型?我當然可以使用CGContextRef的地址並傳遞我想要的所有指針。 – CodaFi