sayguh
sayguh

Reputation: 2550

UIView transition works only if the UIView is created through Interface Builder

I have the code below wired up to a UIButton action... If I create the image view programmatically like below... myImageView does not animate on to the screen (it appears instantly)

UIIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"btn_image.png"]];

 [self.view addSubview:myImageView];
 [myImageView setHidden:YES];

 [UIView transitionWithView:myImageView duration:2 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        [myImageView setHidden:NO];
    } completion:nil];

However, if I first create "myImageView" in Interface Builder and set it's hidden property to true and then wire it up with an outlet the same code works as I want

[UIView transitionWithView:myImageView duration:2 options: UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        [myImageView setHidden:NO];
    } completion:nil];

So... is there something additional that I need to do when creating programatically in order to get this to work? Thanks!

Upvotes: 1

Views: 184

Answers (1)

sayguh
sayguh

Reputation: 2550

Here's a link with tutorial I was able to use to get this to work...

http://www.dizzey.com/development/ios/simple-uiview-transitions-animation-using-blocks-in-ios-4/

You need to have a containerView and it needs to be added to your main view during viewdidload (not during the action where you want the transition to take place)

This works with "addSubView" or "setHidden:NO"

Upvotes: 1

Related Questions