Search code examples
iosuiviewcore-animation

Flipping a view inside a container, revealing a second view


I am currently using this code:

FlipView *fv = [[FlipView alloc]init];
[UIView transitionWithView:flipContainer
                  duration:1
                   options:UIViewAnimationOptionTransitionFlipFromLeft
                animations:^{ 
                    [flipContainer addSubview:fv];
                }
                completion:NULL];

to flip a container view containing a UIImage around to reveal a second view (FlipView). FlipView is a UIView currently with its background set to red for debugging.

What happens now is that the container flips, but it's displaying the same thing as before, despite using:

[flipContainer addSubview:fv];

What am I doing wrong?


Solution

  • What happens if you add the subview without the animation? Does the subview appear? Maybe the subview isn't being initialized properly (such as maybe its frame isn't being set properly?)

    You could try initializing like this:

    CGRect frame = CGRectMake(xOrigin,yOrigin,width,height);
    FlipView *fv = [[FlipView alloc] initWithFrame:frame];
    

    Or try setting the frame property of the FlipView:

    FlipView *fv = [[FlipView alloc]init];
    CGRect frame = CGRectMake(xOrigin,yOrigin,width,height);
    fv.frame = frame;