How to flip a UIButton horizontal with another UIButton on the backside?
I want a button that h开发者_如何学Goas 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 http://img51.imageshack.us/img51/585/welyrics2jpg.png
Thanks for the answer!
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
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];
-(void)viewDidLoad
{
UIButton *btn; = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(x, y, 60, 40);
btn.backgroundColor = [UIColor clearColor];
[btn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
btn.tag=count;
[buttonWithTag setBackgroundImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateNormal];
[btn setTitle:[NSString stringWithFormat:@"%d",btn.tag] forState:UIControlStateNormal];
[view_frame addSubview:btn];
[btn addTarget:self action:@selector(Click:)forControlEvents:UIControlEventTouchUpInside];
}
//action
- (IBAction)Click:(id)sender
{
UIButton *click_btn = (UIButton *)sender;
NSLog(@"%d",click_btn.tag);
UIButton *buttonWithTag = (UIButton *)[view_frame viewWithTag:click_btn.tag];
CATransition *animation = [CATransition animation];
animation.delegate = self;
animation.duration = 1.0;
animation.timingFunction = UIViewAnimationCurveEaseInOut;
animation.fillMode = kCAFillModeForwards;
animation.removedOnCompletion = NO;
animation.type = @"oglFlip";
[buttonWithTag.layer addAnimation:animation forKey:nil];
[buttonWithTag setBackgroundImage:[UIImage imageNamed:@"1.png"] forState:UIControlStateNormal];
}
精彩评论