views:

73

answers:

2
- (void) hideMenu {
  UIView *currentView = [self view];
  [UIView beginAnimations:nil context: nil];
  [UIView setAnimationDuration: 0.5];
  [currentView setFrame:CGRectMake(0, 480, [currentView bounds].size.width, [currentView bounds].size.height)];
  [UIView commitAnimations];

  self.timer = [NSTimer scheduledTimerWithTimeInterval:(.5)
                        target:self
      selector:@selector(removeAfterAnimate)
         userInfo:nil
      repeats:NO];
}


- (void) removeAfterAnimate {
  [self.view removeFromSuperview];  
  NSLog(@"removed the view");
}
A: 

Shouldn't you put the removeFromSuperview inside the animation block? Don't you want to animate it rotating away or whatever. And nothing will happen right now because you didn't set

[UIView setAnimationTranstion:(ex. UIViewAnimationTransitonFlipFromRight) forView:(ex. self.view) cache:YES];
Mk12
+2  A: 

It would be helpful to better explain "a really strange way" here. It looks like your goal is to move currentView to a particular place and then have your view vanish? Did you mean to use self.view or currentView in both cases?

Don't use an NSTimer here. NSTimers aren't appropriate for animations. Use +setAnimationDidStopSelector:. Something like this:

- (void) hideMenu {
  UIView *currentView = [self view];
  [UIView beginAnimations:@"hideMenu" context:currentView];
  [UIView setAnimationDuration: 0.5];
  [UIView setAnimationDelegate:self];
  [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
  [currentView setFrame:CGRectMake(0, 480, [currentView bounds].size.width, [currentView bounds].size.height)];
  [UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
  [self.view removeFromSuperview];
  NSLog(@"removed the view");
}
Rob Napier