0

終了したタッチに以下のコードを使用しています。いくつかの uiview を少し動かした後、次のようにコードでセグエを呼び出します: [self performSegueWithIdentifier: @"segueToLevel2" sender: self]

セグエのトランジション タイプは「クロス ディゾルブ」に設定されています。

以下のコードでは、レベル 5 に到達するまですべて正常に動作します。レベル 5 でセグエが呼び出されると、クロス ディゾルブの代わりにコーナー ツー コーナー フリップが実行され、この時点から、アプリ内のすべてのセグエで、何の代わりにこのフリップが実行されます。彼らはするように設定されていました。タッチを終了したメソッドを取り出すと、すべてが期待どおりに機能するため、問題はここにあるはずです。これがレベル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 に答える