10

iPhone / Objective-C

On my view a little "hover" view appears after a user clicks on a button on the main view. When the user clicks this subview I want the subview to FlipFromRight to another view (same size). The main view underneath should stay.

viewHot and viewCold are the subviews viewMain is the main one.

Is this possible?

Ian Vink
  • 66,960
  • 104
  • 341
  • 555
  • I have used the following code..it works fine..but one problem.. I have a tableView in viewHot. When "else" part get executed viewHot appears. But coldView is still behind the viewHot so when I scroll tableView to maximum or minimum the coldView is seen.. any guesses ? – Maulik Nov 22 '11 at 10:14
  • I tried removeFromSuperView , hidden = YES etc but no Luck.. !!! – Maulik Nov 22 '11 at 10:14

1 Answers1

22

Create another empty view in viewMain called viewHover and position it where you want the hover views to show. Then in IB add either viewHot or viewCold (not both) as a subview of viewHover.

Then call a method like this to flip the views:

-(void)flipViews
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.0];  
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:viewHover cache:YES];

    if ([viewHot superview])
    {
        [viewHot removeFromSuperview];
        [viewHover addSubview:viewCold];
        [viewHover sendSubviewToBack:viewHot];
    }
    else
    {
        [viewCold removeFromSuperview];
        [viewHover addSubview:viewHot];
        [viewHover sendSubviewToBack:viewCold];
    }

    [UIView commitAnimations];
}
  • 2
    This code helped me in presenting a small modal view. Thank you. – Sasho Sep 18 '10 at 08:25
  • 8
    Just an FYI, with the new animation blocks the animation can be one-lined: [UIView transitionFromView:viewHot toView:viewCold duration:1.f options:UIViewAnimationOptionTransitionFlipFromLeft completion:nil]; – yuf Oct 29 '12 at 18:37