PDA

View Full Version : Flip View in iPhone SDK




jmac1074
May 18, 2008, 05:51 PM
Can anyone tell me how to flip the view of an iPhone application, similar to the weather application?

thanks.

Jmac



Sbrocket
May 18, 2008, 06:08 PM
See my reply here:
http://forums.macrumors.com/showthread.php?t=477617&highlight=flip+view

And try using the forum search next time.

jmac1074
May 19, 2008, 05:11 AM
I had used the search function and I found your reply. However there is no theElements example on the dev center.

Sbrocket
May 19, 2008, 07:01 AM
Ah, they must have removed it. The same sample code is in UIShowcase. I think the specific class is FlipViewController, or something like that.

mpemburn
Jun 24, 2012, 07:04 AM
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:



- (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