2

I have a button which when pressed pushes a view controller however i'm using a custom animation so pushViewController: childController animated: is set to NO. What i want to do though is detect this custom animation in my - (void)viewWillAppear:(BOOL)animatedmethod and write an if statement like this;

- (void)viewWillAppear:(BOOL)animated { 
     if (customAnimation occured) {//Do this} 
     else {//Do this}
}

This is the method for my button which pushes the view controller.

- (void)nextPressed:(id)sender {
    childController = [[CategoryOneDetailController alloc] initWithNibName:xibDownName bundle:nil];
    [UIView  beginAnimations: @"Showinfo"context: nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.navigationController pushViewController: childController animated:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];
    [childController release];
}

Any help would be much appreciated, thanks, Sami.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Sami
  • 1,374
  • 1
  • 16
  • 43

1 Answers1

1

If you don't use standard animations, I think your best bet is to add a property to your pushed view controller that is set to YES in case of a custom animation (and NO by default to not break any existing behavior). Then you can check that property in viewDidAppear:.

If you need your custom logic to be executed after the animation has run, you might want to set up an animation completion handler or block.

Eiko
  • 25,601
  • 15
  • 56
  • 71
  • Thanks, for the response, how would i add a property to my view controller, sorry i'm still learning. – Sami Jun 23 '11 at 08:40
  • 1
    Just like any other code you write. Add a variable `BOOL usesCustomAnimation;` and `@property BOOL usesCustomAnimation;`in your controller's .h file, and `@synthesize usesCustomAnimation;`in your .m file. Then, after you alloc/init your controller, just do `childController.usesCustomAnimation = YES;`. – Eiko Jun 23 '11 at 08:44
  • Thanks, it all worked great, i was on the right track, was using an NSString instead of a BOOL however i was missing this part 'childController.usesCustomAnimation = YES;'. – Sami Jun 23 '11 at 09:12
  • I don't suppose you could help with another small issue, when the nextPressed method is called i would like to hide a label then run the custom animation, so i added the following code [label setAlpha:0]; before the animation however it doesn't work the label is not hidden so i tried adding a timer before the animation [NSThread sleepForTimeInterval:1]; but still no luck, any idea why? – Sami Jun 23 '11 at 09:25
  • Check if label is nil, maybe it's not connected. – Eiko Jun 23 '11 at 09:44
  • I added the label programmatically, and i know it works because if i disable the the pushing of the view controller so that if the button is pressed just the label is hidden then it works, it just doesn't work when i have both. – Sami Jun 23 '11 at 10:18
  • It should. Maybe put this up with some code as another question. – Eiko Jun 23 '11 at 10:43