I can’t figure out why this UIView doesn’t display correctly when the method is called. It works in another view controller. When I try it in the RootViewController the NSLog output works fine, but no view animates. I’m wondering if it does display but is hidden from view. Any help would be great.
- (IBAction)showView:(id)sender{
NSLog(@"showView button pressed");
[self.view addSubview: menuView];
[self.view bringSubviewToFront:menuView];
CGRect rect = menuView.frame;
rect.origin.x = 60;
rect.origin.y = -400;
menuView.frame = rect;
[UIView beginAnimations:@"ShowView" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
rect.origin.y = 65;
menuView.frame = rect;
[UIView commitAnimations];
}
This worked in your RootViewController, then you copied the showView: code into a new view controller and it doesn’t work. Your conversation with @kl94 explains the rest. The menuView has been declared but not initialized in the new view controller.
I think if you go back to RootViewController where it’s working, you’ll find code where menuView is initialized: …menuView = [[SomeViewClass alloc] init….. That code needs to get copied to the new view controller, too. A decent place to put it is in the viewDidLoad method.
I agree with @Amiramix that the block animation is the way to go. I’d suggest code as follows: