`
01jiangwei01
  • 浏览: 533025 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

iOS 动画一

    博客分类:
  • IOS
 
阅读更多
//
//  ViewController.m
//  AnimationY
//
//  Created by ldci on 13-4-14.
//  Copyright (c) 2013年 ldci. All rights reserved.
//

#import "ViewController.h"
#import "QuartzCore/QuartzCore.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    [_pView release];
    [_imgView1 release];
    [_imgView2 release];
    [_pView release];
    [super dealloc];
}
- (IBAction)butUP:(id)sender {
    
    [UIView  beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    
    //找到image View的父View
    UIView *beginView = self.pView;
    //将卷曲动画应用到父View
    //UIViewAnimationTransitionCurlUp
    [UIView  setAnimationTransition:  UIViewAnimationTransitionCurlDown forView:beginView cache:YES];
    
    [beginView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    
    [UIView commitAnimations];
    
}

- (IBAction)btnLeft:(id)sender {
    
    [self actAnimation:0];
}

- (IBAction)btnDown:(id)sender {
    [self actAnimation:1];
}

- (IBAction)btnRight:(UIButton *)sender {
    [self actAnimation:2];
}

- (IBAction)btnCenter:(id)sender {
    [self actAnimation:3];
}
-(void)actAnimation:(int) type{
    CATransition *animation = [CATransition animation];
    animation.duration = 1.0f;
    animation.timingFunction= UIViewAnimationCurveEaseInOut ;
    switch(type){
        case  0://淡入淡出
            animation.type = kCATransitionFade;
             break;
        case 1://滑入
            animation.type = kCATransition;
             break;
        case 2://推进
            animation.type = kCATransitionPush;
            break;
        case 3://
            animation.type = kCATransitionReveal;
             break;
    }
    //预定义一个基础变化
    animation.subtype = kCATransitionFromRight;
    UIView *beginView = self.pView;
    //将卷曲动画应用到父View
    //UIViewAnimationTransitionCurlUp
    [UIView  setAnimationTransition:  UIViewAnimationTransitionCurlDown forView:beginView cache:YES];
    
    [beginView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];

//    应用动画
    [[beginView layer ]addAnimation:animation forKey:nil];
    
    

}
@end

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics