Im using the below code for touches ended. After a few uiviews 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 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.
-(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;
}
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.