首页 > 其他 > 详细

切换view的动画

时间:2014-10-08 10:58:25      阅读:256      评论:0      收藏:0      [点我收藏+]

代码:

#import "MainViewController.h"

@interface MainViewController ()

@end

@implementation MainViewController


- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIView *view1 = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    view1.backgroundColor = [UIColor blueColor];
    
    UIView *view2 = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    view2.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:view1];
    [self.view addSubview:view2];
}

-(void) changeView
{
    NSLog(@"change view");
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
       
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:nil];
    [UIView commitAnimations];
}

-(void) changeView2
{
    CATransition *animation = [CATransition animation];
    [animation setDuration:1.25f];
    [animation setTimingFunction:[CAMediaTimingFunction
                                  functionWithName:kCAMediaTimingFunctionEaseIn]];
    [animation setType:kCATransitionReveal];
    [animation setSubtype: kCATransitionFromRight];
    [self.view.layer addAnimation:animation forKey:@"Reveal"];
    
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
   
    [CATransaction commit];
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self changeView];
}
@end

 

切换view的动画

原文:http://www.cnblogs.com/code-style/p/4010616.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!