- (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實現爲實際代碼?
此代碼不起作用,因爲沒有當前上下文。如何繪製:http://www.apeth.com/iOSBook/ch15.html – matt