简体   繁体   中英

Simple UIView animation move doesn't work

I have no idea, why it is not working.

All I want to do is a simple UIView animation in the viewDidLoad.

Here's my code:

[UIView animateWithDuration:3.0f animations:^{
    [self.headline setCenter:CGPointMake(0.0, 200.0)];
}];

Nothing happens. When I test the general approach of calling a animation method on that particular object like this:

[UIView animateWithDuration:3.0f animations:^{
    [self.headline setAlpha:0.0];
}];

it works!!! Why am I not able to move the view across the screen? I am using latest Xcode 4.5.

Thanks for any advice!

UPDATE:

When I add a view manually in code it works. But for the UIViews I create as Outlets in the Interface Builder it doesn't work.

UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
testLabel.backgroundColor = [UIColor redColor];

[self.view addSubview:testLabel];

[UIView animateWithDuration:3.0 animations:^{
    testLabel.center = CGPointMake(0.0, 200);
}];

So obviously I am doing something wrong in the .xib file

Dont do it in viewDidLoad. The view is not pressent at that time yet. Try it in viewDidAppear.

Well, I think the reason for the missing animation was the fact that I called a different push navigation animation from the view controller that was pushing the actual view on screen:

- (IBAction)goForSelection:(id)sender
{
    SelectionViewController *selectionViewController = [[SelectionViewController alloc] initWithNibName:@"SelectionViewController" bundle:nil];

    //[self.navigationController pushViewController:selectionViewController animated:YES];

    [UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        [self.navigationController pushViewController:selectionViewController animated:NO];
    } completion:^(BOOL finished) {
        [selectionViewController startIntroAnimation];
    }];
}

First I checked what happens when I use the default navigation controller segue. And to my surprise the animation did start. Then I inserted the call to the [selectionViewController startIntroAnimation] to the completion block and this works as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM