views:

355

answers:

2

Hello, I want a button that has a another button on the backside. When you press the button it should flip horizontal and show the other button. Apple did this in the ipod-App. When you hear a song you can press the button on the right site of the navigationbar and then the view flips and you can see all the songs from the album. But the interest point is that the button on the right side flips with the view horizontal. How can I do this?

alt text

Thanks for the answer!

+2  A: 

I dont understand this atm.

My iPhone coach did it for me a while back.. but i wasnt looking at what he did.

So heres the code. .h

#import <UIKit/UIKit.h>

@interface flipTesViewController : UIViewController {
IBOutlet UIView *containerView;

UIImageView *heads;
UIImageView *tails;
}
-(IBAction)test;

@end

.m

#import "flipTesViewController.h"

 @implementation flipTesViewController





-(IBAction)test{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(test)];
[UIView setAnimationDuration:.5];
if(heads.tag==1){
    [containerView addSubview:heads];
    heads.tag=2;
}
else{
    [containerView addSubview:tails];
    heads.tag=1;
}

[UIView commitAnimations];
}



- (void)viewDidLoad {
[super viewDidLoad];

heads = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NZHeads.png"]];
tails = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"NZTails.png"]];

[containerView addSubview:heads];

}
//other method built in to view based template
@end
Sam Jarman
That's the way to do it.Creating an AnimationBlock and defining what to do in it. The iPhone SDK knows how to handle the rest... the AnimationBlocks are very powerful and are perfect for creating stylish animations.You could use anything, from adding a subview to applying a transform.
natanavra
+1  A: 

On 3.x there's a simpler way:

  • Make the "backside view" as a UIViewController or one of its subclasses.
  • When the your "flip" button is pressed, call

.

backsideViewCtrler.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:backsideViewCtrler animated:YES];
KennyTM