0

我使用下面的代码进行触摸结束。在移动了一些 uiview 之后,我在我的代码中调用了一个 segue,如下所示: [self performSegueWithIdentifier: @"segueToLevel2" sender: self]

segue 的过渡类型设置为“交叉溶解”。

使用下面的代码,一切正常,直到我达到第 5 级。在第 5 级,当调用 segue 时,它​​会进行角到角翻转而不是交叉溶解,从这一点开始,我的应用程序中的每个 segue 都会进行此翻转而不是什么他们打算这样做。如果我拿出我的触摸结束方法,一切都会按预期工作,所以问题一定就在这里。我只是想不通为什么这适用于 1-4 级,但在 5 级上无效。任何帮助将不胜感激......我在这里失去了理智。

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
switch (level) {
    case 1:{

        if ((piece11.hidden == YES) && (piece1moving.hidden == NO) && (piece1placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece1moving.frame = CGRectMake(-65, 153, 490, 422);
            [UIView commitAnimations];
            [NSTimer scheduledTimerWithTimeInterval:3 target:(self) selector:@selector(moveToFront) userInfo:(nil) repeats:NO];
            [NSTimer scheduledTimerWithTimeInterval:1 target:(self) selector:@selector(singlePieceCallback) userInfo:(nil) repeats:NO];   

        }    
    }
        break;
    case 2:{
        UITouch *touch1 = [[event allTouches] anyObject];
        if (([touch1 view] == piece1) && (piece1placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece1.frame = CGRectMake(47, 402, 305, 312);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece2) && (piece2placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece2.frame = CGRectMake(34, 4, 291, 399);
            [UIView commitAnimations];
        }
    }
        break;
    case 3:{
        UITouch *touch1 = [[event allTouches] anyObject];
        if (([touch1 view] == piece1) && (piece1placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece1.frame = CGRectMake(1, 419, 308, 356);
            [UIView commitAnimations];


        }
        if (([touch1 view] == piece2) && (piece2placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece2.frame = CGRectMake(-7, 67, 291, 315);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece3) && (piece3placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece3.frame = CGRectMake(-16, 169, 427, 310);
            [UIView commitAnimations];

        }
    }
        break;
    case 4:{
        UITouch *touch1 = [[event allTouches] anyObject];

        if (([touch1 view] == piece1) && (piece1placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece1.frame = CGRectMake(0, 76, 219, 261);
            [UIView commitAnimations];


        }
        if (([touch1 view] == piece2) && (piece2placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece2.frame = CGRectMake(89, 485, 255, 287);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece3) && (piece3placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece3.frame = CGRectMake(103, 197, 305, 330);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece4) && (piece4placedstate == 0)){
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece4.frame = CGRectMake(5, 277, 228, 294);

        }

    }
        break;
    case 5:{
        UITouch *touch1 = [[event allTouches] anyObject];
        if (([touch1 view] == piece1) && (piece1placedstate == 0)) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece1.frame = CGRectMake(115, 89, 247, 263);
            [UIView commitAnimations];


        }
        if (([touch1 view] == piece2) && (piece2placedstate == 0)) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece2.frame = CGRectMake(14, 497, 211, 271);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece3) && (piece3placedstate == 0)) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece3.frame = CGRectMake(92, 248, 244, 272);
            [UIView commitAnimations];

        }
        if (([touch1 view] == piece4) && (piece4placedstate == 0)) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece4.frame = CGRectMake(87, 458, 228, 294);

        }
        if (([touch1 view] == piece5) && (piece5placedstate == 0)) {
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationDuration:1.0];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
            piece5.frame = CGRectMake(-13, 102, 244, 303);

        }
    }
        break;


    default:
        break;
}
4

1 回答 1

1

我仍然不确定是什么导致了上述代码出现问题,但我找到了一种解决方案,可以重写我的代码并使用 UIPanGestureRecognizer,如下面的每个部分所附。这在整个过程中都非常有效。

- (void) dragGesture5:(UIPanGestureRecognizer *) panGesture {
CGPoint translation = [panGesture translationInView:self.view];

switch (panGesture.state) {
    case UIGestureRecognizerStateBegan:{

        originalCenter = piece5.center;
        [self.view bringSubviewToFront:piece5];


    }
        break;
    case UIGestureRecognizerStateChanged:{

        piece5.center = CGPointMake(piece5.center.x + translation.x,
                                     piece5.center.y + translation.y);
        [self checkColision];


    }
        break;
    case UIGestureRecognizerStateEnded:{            

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:1.0];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
        piece5.center = originalCenter;
        [UIView commitAnimations];




    }
        break;
    default:
        break;
}

[panGesture setTranslation:CGPointZero inView:self.view];
}
于 2012-10-02T04:31:19.647 回答