#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Touches ended is causing issues with segue animation


    Im making a fairly simple app for the iPad using xCode (written in objective c of course).

    Im using the below code for touches ended. After a few uiimageviews are moved around a bit I call a segue in my code like this: [self performSegueWithIdentifier: @"segueToLevel2" sender: self]

    The segue's transition types are set to "cross dissolve".

    With the code below everything works fine until I get to level 5. On level five when the segue is called it does a corner to corner flip instead of the cross dissolve and from this point on every segue in my app does this flip instead of what they were set to do. If I take out my touches ended method everything works as expected so it seems the problem must be here. I just cant figure out why this works for levels 1-4 but craps out on level 5. Any help would be greatly appreciated....im loosing my mind here.


    Code:
    -(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;
    }
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    I'm still not sure what was causing my issue with the above code but I have found a solution in re-writing my code and using a UIPanGestureRecognizer like the one below attached to each of the pieces. This works perfectly throughout.

    Code:
    - (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];
    }

IMN logo majestic logo threadwatch logo seochat tools logo