Skip to content

Instantly share code, notes, and snippets.

@xdream86
Created August 25, 2013 03:39
Show Gist options
  • Save xdream86/6331856 to your computer and use it in GitHub Desktop.
Save xdream86/6331856 to your computer and use it in GitHub Desktop.
-(void)viewDidLoad{
[super viewDidLoad];
UIButton *btnFlip = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btnFlip.frame = CGRectMake(10, 10, 50, 30);
[btnFlip setTitle:@"flip" forState:UIControlStateNormal];
[btnFlip addTarget:self action:@selector(flip) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnFlip];
panel = [[UIView alloc] initWithFrame:CGRectMake(10, 40, 300,300)];
panel.backgroundColor = [UIColor darkGrayColor];
[self.view addSubview:panel];
panelBack = [[UIView alloc] initWithFrame:CGRectMake(10, 40, 280, 200)];
panelBack.tag = 1;
panelBack.backgroundColor = [UIColor brownColor];
[panel addSubview:panelBack];
panelFront = [[UIView alloc] initWithFrame:CGRectMake(10, 40, 280, 200)];
panelFront.tag = 2;
panelFront.backgroundColor = [UIColor whiteColor];
[panel addSubview:panelFront];
displayingFront = TRUE;
}
-(void)flip{
[UIView transitionWithView:panel
duration:0.5
options:(displayingFront ? UIViewAnimationOptionTransitionFlipFromRight : UIViewAnimationOptionTransitionFlipFromLeft)
animations:^{
if (displayingFront) {
//panelFront.hidden=TRUE;
//panelBack.hidden = FALSE;
[panelFront removeFromSuperview];
[panel addSubview:panelBack];
}else{
//panelFront.hidden=FALSE;
//panelBack.hidden = TRUE;
[panelBack removeFromSuperview];
[panel addSubview:panelFront];
}
}
completion:^(BOOL finished){
displayingFront = !displayingFront;
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment