Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created December 11, 2010 10:00
Show Gist options
  • Save marshluca/737296 to your computer and use it in GitHub Desktop.
Save marshluca/737296 to your computer and use it in GitHub Desktop.
视图切换效果, slide, fade, flip
- (void) fadeOut: (id) sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[[self.view viewWithTag:999] setAlpha:0.0f];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Fade In", @selector(fadeIn:));
}
- (void) fadeIn: (id) sender
{
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
[[self.view viewWithTag:999] setAlpha:1.0f];
[UIView commitAnimations];
self.navigationItem.rightBarButtonItem = BARBUTTON(@"Fade Out", @selector(fadeOut:));
}
- (void) info
{
int segment = [(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex];
int styles[3] = {
UIModalTransitionStyleCoverVertical,
UIModalTransitionStyleCrossDissolve,
UIModalTransitionStyleFlipHorizontal
};
InfoViewController *ivc = [[[InfoViewController alloc] init] autorelease];
ivc.modalTransitionStyle = styles[segment];
[self presentModalViewController:ivc animated:YES];
}
- (void) swap: (id) sender
{
// hide the button
self.navigationItem.rightBarButtonItem = nil;
UIView *frontObject = [[self.view subviews] objectAtIndex:2];
UIView *backObject = [[self.view subviews] objectAtIndex:1];
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:1.0];
frontObject.alpha = 0.0f;
backObject.alpha = 1.0f;
frontObject.transform = CGAffineTransformMakeScale(0.25f, 0.25f);
backObject.transform = CGAffineTransformIdentity;
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationFinished:)];
[UIView commitAnimations];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment