Flip View in iPhone SDK

Discussion in 'iOS Programming' started by jmac1074, May 18, 2008.

  1. macrumors newbie

    Joined:
    Apr 24, 2008
    #1
    Can anyone tell me how to flip the view of an iPhone application, similar to the weather application?

    thanks.

    Jmac
     
  2. macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
  3. thread starter macrumors newbie

    Joined:
    Apr 24, 2008
    #3
    I had used the search function and I found your reply. However there is no theElements example on the dev center.
     
  4. macrumors 65816

    Sbrocket

    Joined:
    Jun 3, 2007
    Location:
    /dev/null
    #4
    Ah, they must have removed it. The same sample code is in UIShowcase. I think the specific class is FlipViewController, or something like that.
     
  5. macrumors member

    Joined:
    Jan 11, 2008
    Location:
    Bel Air, MD USA
    #5
    The main page for TheElements is here: http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html#//apple_ref/doc/uid/DTS40007419-Intro-DontLinkElementID_2

    I tried downloading the sample code but the ZIP file was empty :-( The class that contains the page flip code is AtomicElementViewController.m and the specific method is flipCurrentView:


    Code:
    - (void)flipCurrentView {
        NSUInteger reflectionHeight;
        UIImage *reflectedImage;
        
        // disable user interaction during the flip
        containerView.userInteractionEnabled = NO;
        flipIndicatorButton.userInteractionEnabled = NO;
        
        // setup the animation group
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(myTransitionDidStop:finished:context:)];
        
        // swap the views and transition
        if (frontViewIsVisible==YES) {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:YES];
            [atomicElementView removeFromSuperview];
            [containerView addSubview:atomicElementFlippedView];
            
            
            // update the reflection image for the new view
            reflectionHeight=atomicElementFlippedView.bounds.size.height*reflectionFraction;
            reflectedImage = [atomicElementFlippedView reflectedImageRepresentationWithHeight:reflectionHeight];
            reflectionView.image=reflectedImage;
        } else {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
            [atomicElementFlippedView removeFromSuperview];
            [containerView addSubview:atomicElementView];
            // update the reflection image for the new view
            reflectionHeight=atomicElementView.bounds.size.height*reflectionFraction;
            reflectedImage = [atomicElementView reflectedImageRepresentationWithHeight:reflectionHeight];
            reflectionView.image=reflectedImage;
        }
        [UIView commitAnimations];
        
        
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.75];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(myTransitionDidStop:finished:context:)];
        
        if (frontViewIsVisible==YES)
        {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:flipIndicatorButton cache:YES];
            [flipIndicatorButton setBackgroundImage:element.flipperImageForAtomicElementNavigationItem forState:UIControlStateNormal];
        }
        else
        {
            [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:flipIndicatorButton cache:YES];
            [flipIndicatorButton setBackgroundImage:[UIImage imageNamed:@"flipper_list_blue.png"] forState:UIControlStateNormal];
            
        }
        [UIView commitAnimations];
        frontViewIsVisible=!frontViewIsVisible;
    }
    
    Hope that helps
     

Share This Page