开发者

iPhone - UIView animation problem in viewDidLoad / viewDidAppear

I have a UIView that contains a subview called 开发者_如何转开发menuView managed by a MenuViewController.

I wrote that code :

- (void) viewDidLoad
{
    [self.menuView setFrame:CGRectOffset(self.menuView.frame, 0.0, self.menuView.frame.size.height)];
    [super viewDidLoad];
}

- (void) viewDidAppear:(BOOL)animated
{
    [UIView beginAnimations:@"SomeAnimation" context:nil];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.menuView cache:YES];           
    [self.menuView setFrame:CGRectOffset(self.menuView.frame, 0.0, -self.menuView.frame.size.height)];

    [UIView commitAnimations];

    [super viewDidAppear:animated];   // tried at begining too
}

But when loaded, no animation is visible... I also tried with viewWillAppear with no change.

it is called outside MenuViewController with :

- (IBAction) showMenu
{
    MenuViewController* menuController = [[MenuViewController alloc] initWithNibName:@"Menu" bundle:nil];];
    [self.view addSubview:menuController.view];
//    [menuController release];   for try
}

What's the problem ?

P.S. : What I want to do is when the view is displayed, some part of that view (the menuView) move. That view (partially transparent) is intended to cover a superview that is owned by another ViewController.


Are you calling the viewDidAppear method from your view controller? Some controllers, such as the UINavigationController, will take care of that, but if you're using a custom controller, you'll need to call it. Typically, you would call viewWillAppear, then add the view, the call viewDidAppear.

So your code block would be:

- (IBAction) showMenu
{
    MenuViewController* menuController = [[MenuViewController alloc] initWithNibName:@"Menu" bundle:nil];];
    [menuController viewWillAppear:YES];
    [self.view addSubview:menuController.view];
    [menuController viewDidlAppear:YES];
    [menuController release];
}


Can you confirm that self.menuView is actually properly initialized and is not nil?


Perhaps you should first call the super initialization of your method ?

[super viewDidAppear:animated]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜