0

I have button on page 1 when i click on button i am performing some animation and navigation to new page say Page 2.

On page 2 there is cancel button when i click on that i want to go back to my previuos page i.e Page 1 but on click of cancel button my app crashes.

Here is my sample code on Page 1:Name of page CRViewController

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self.view addSubview:secondController.view];
}

Code which is on Page 2: Name of page RegistraionViewController (on Which crashes on click.)

- (IBAction)Click:(id)sender {
    CRViewController *secondController = [[CRViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromTop];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self.view addSubview:secondController.view];
}
Krunal
  • 6,440
  • 21
  • 91
  • 155

3 Answers3

1

Try this:

- (IBAction)ClickMe:(id)sender {   
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];   
    [self.navigationController pushViewController:secondController animated:YES];   
}


- (IBAction) Click:(id)sender {    
   [self.navigationController popViewControllerAnimated:YES];    
}

Edit:
I'm sorry. If you want custom some UIViewController transitions animation, see below:
UIViewController transition - objective-c
http://www.teehanlax.com/blog/custom-uiviewcontroller-transitions/
Or you can try this:

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil];
    [self.navigationController pushViewController:secondController animated:NO]; 
}

- (IBAction)Click:(id)sender {
    CRViewController *secondController = [[CRViewController alloc] init];

    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromTop];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];

    [self.navigationController.view.layer addAnimation:transitionAnimation forKey:nil];
    [self.navigationController popToViewController:secondController animated:NO];
}
Community
  • 1
  • 1
Vincent Sit
  • 2,214
  • 1
  • 24
  • 27
0

Your problem is lying somewhere because of the subview. I have tried your code.

I did the following code in my project with some animation hope it helps you.

CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];
    [animation setDuration:0.8];
    [animation setType:kCATransitionFade];
    [animation setSubtype:kCATransitionMoveIn];

    //[[self.view layer]addAnimation:animation forKey:@"fview"];

    [self.navigationController.view.layer addAnimation:animation forKey:nil];

    [self.navigationController pushViewController:yourView animated:NO];

In animation type you can give whichever animation you want.

Hope that helps you.

Manthan
  • 3,856
  • 1
  • 27
  • 58
  • Unable to see animation :( – Krunal Oct 30 '13 at 10:15
  • I am running this code in my project right now man. Check it if you have pass the correct view name in it. In your code if you push the view rather than subviewing it it is showing you animation. – Manthan Oct 30 '13 at 10:18
  • `RegistraionViewController *secondController = [[RegistraionViewController alloc] init];CATransition *animation = [CATransition animation];[animation setDelegate:self];[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]];[animation setDuration:0.8];[animation setType:kCATransitionFade]; [animation setSubtype:kCATransitionMoveIn]; [self.navigationController.view.layer addAnimation:animation forKey:nil];[self.navigationController pushViewController:secondController animated:NO];` – Krunal Oct 30 '13 at 10:32
  • I tried above code, animation comes but after animation it loads same file. – Krunal Oct 30 '13 at 10:33
  • Then check if you are passing a view onto which you want to nevigate. And don't take same names for the object of different view controllers. – Manthan Oct 30 '13 at 10:55
  • I tried just now. It is working man. You would have done some mistake. – Manthan Oct 30 '13 at 10:58
  • If i simply write: `RegistraionViewController *secondController = [[RegistraionViewController alloc] init]; [self.navigationController pushViewController:secondController animated:YES];` still i am unable to navigate to new page – Krunal Oct 30 '13 at 11:04
  • It is not opening. Did you put breakpoint and check that if it goes in your method? and try to give name of your xib with initwithnibname and check. – Manthan Oct 30 '13 at 11:19
  • You can tell me in chat and write your code and i will help you. – Manthan Oct 30 '13 at 11:57
0

*

- (IBAction)ClickMe:(id)sender {
    RegistraionViewController *secondController = [[RegistraionViewController alloc] init];
    CATransition *transitionAnimation = [CATransition animation];
    [transitionAnimation setDuration:1];
    [transitionAnimation setType:@"push"];
    [transitionAnimation setSubtype:kCATransitionFromBottom];
    [transitionAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault]];
    [self.view.layer addAnimation:transitionAnimation forKey:kCATransitionFromBottom];
    [self addChildViewController:secondController];
    [self.view addSubview:secondController.view];
}

* replace your sample code on Page 1: with the above and then check.

Hope this helps to you

MadhuP
  • 2,019
  • 17
  • 22