这是我的UIPanGestureRecognizer
- (void)SwipeHandle:(UIPanGestureRecognizer*)gestureRecognizer
{
UIView *theSuperview = self.numberview;
CGPoint touchPointInSuperview = [gestureRecognizer locationInView:theSuperview];
float gapX = image1.frame.size.width / 8;
float gapY = image1.frame.size.height / 8.48;
if(gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
if(!ispause && [time.text intValue] > 0){
if(!isbegan && !isended){
for(int i = 1; i <= 16; i++)
{
UIView *imageview = [self.numberview viewWithTag:i];
if (CGRectContainsPoint(imageview.frame, touchPointInSuperview))
{
isbegan = YES;
isreverse = NO;
if([[ischose objectAtIndex:i-1] boolValue] == 0)
{
currentposition = imageview.tag;
positionvalue += pow(i, 3);
currentanswer += [self converter:[NSString stringWithFormat:@"%@", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
[ischose replaceObjectAtIndex:i-1 withObject:[NSNumber numberWithBool:YES]];
[self changeimage:@"selected"];
}
previouspoint = imageview.frame.origin;
break;
}
}
}
}
}
else if(gestureRecognizer.state == UIGestureRecognizerStateChanged)
{
if(isbegan && !isended)
{
if(touchPointInSuperview.x >= 0 && touchPointInSuperview.x <= self.numberview.frame.size.width && touchPointInSuperview.y >= 0 && touchPointInSuperview.y <= self.numberview.frame.size.height)
{
for(int i = 1; i <= 16; i++)
{
UIImageView *imageview = (UIImageView*)[self.numberview viewWithTag:i];
if (CGRectContainsPoint(imageview.frame, touchPointInSuperview))
{
if((touchPointInSuperview.x >= imageview.frame.origin.x + gapX && touchPointInSuperview.x < imageview.frame.origin.x + imageview.frame.size.width - gapX) && (touchPointInSuperview.y >= imageview.frame.origin.y + gapY && touchPointInSuperview.y < imageview.frame.origin.y + imageview.frame.size.height - gapY ))
{
if([[ischose objectAtIndex:i-1] boolValue] == 0 && !isreverse)
{
currentposition = imageview.tag;
positionvalue += pow(i, 3);
currentanswer += [self converter:[NSString stringWithFormat:@"%@", [allimagenumbers substringWithRange:NSMakeRange(i-1, 1)]]];
[ischose replaceObjectAtIndex:i-1 withObject:[NSNumber numberWithBool:YES]];
[self changeimage:@"selected"];
currentpoint = imageview.frame.origin;
[self.numberview drawRect:CGRectMake(self.numberview.frame.origin.x, self.numberview.frame.origin.y, self.numberview.frame.size.width, self.numberview.frame.size.height)];
UIGraphicsBeginImageContext(imageview.frame.size);
CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(UIGraphicsGetCurrentContext(), red);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), previouspoint.x, previouspoint.y);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0f);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentpoint.x,currentpoint.y);
CGContextClosePath(UIGraphicsGetCurrentContext());
previouspoint = currentpoint;
}
else
{
if(currentposition != imageview.tag)
{
isreverse = YES;
}
else
{
isreverse = NO;
}
}
break;
}
}
}
}
else
{
isended = YES;
isoutofbound = YES;
if(isbegan && isoutofbound)
[self countinganswer];
}
}
}
else if(gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
if(!isoutofbound)
{
isended = YES;
[self countinganswer];
}
else
isoutofbound = NO;
}
}
我试图画一条线,但无法画线。
问题是什么?可以给我一个示例项目吗?