触摸结束导致segue动画出现问题

时间:2012-09-28 11:27:22

标签: objective-c xcode animation segue touch-event

我使用以下代码进行触摸结束。在几个uiviews被移动了一下后,我在我的代码中调用了一个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;
}

1 个答案:

答案 0 :(得分:0)

我仍然不确定是什么原因造成了上述代码的问题,但是我找到了一个重新编写代码并使用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];
}