Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jmac1074

macrumors newbie
Original poster
Apr 24, 2008
6
0
Can anyone tell me how to flip the view of an iPhone application, similar to the weather application?

thanks.

Jmac
 
I had used the search function and I found your reply. However there is no theElements example on the dev center.
 
Ah, they must have removed it. The same sample code is in UIShowcase. I think the specific class is FlipViewController, or something like that.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.