View动画

有两种动画

  1. 首尾动画
UIView beginAnimations:@"第一个UIView动画" context:nil];
//动画和试图的一些属性设置
[UIView commitAnimations];

2.block动画

[UIView animateWithDuration:1 animations:^{

    } completion:^(BOOL finished) {

}

这里block可以嵌套。
设置View的变化使用UIView的transform属性。

下面就是源代码了,这一节不是很难。但后面的那个专场动画要记住。

#import "ViewController.h"

@interface ViewController ()
- (IBAction)firstButton:(UIButton *)sender;
- (IBAction)secondButton:(UIButton *)sender;
@property (retain, nonatomic) IBOutlet UIView *smallView;
- (IBAction)transtimAnimate:(UIButton *)sender;

@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.
}

/*
 语法形式
 [UIView beginAnimations:@"动画的名字" congtext:@"传给代理所执行的方法后面的参数"];




 */
#pragma mark ----------首尾动画
- (IBAction)firstButton:(UIButton *)sender {

    //开始动画
    [UIView beginAnimations:@"第一个UIView动画" context:nil];

    //动画和试图的一些属性设置

    //设置动画执行时间
    [UIView setAnimationDuration:1];

    //动画重复次数
    [UIView setAnimationRepeatCount:1];

    //设置试图的相关属性

//    _smallView.center = CGPointMake(160, 450);

//    改变大小
//    CGRect rect = _smallView.frame;
//    
//    rect.size.width = 80;
//    rect.size.height = 80;
//    
//    _smallView.frame = rect;

    //设置动画延迟执行时间
//    [UIView setAnimationDelay:1];

    //设置动画的曲线
    [UIView setAnimationCurve:3];

    //设置动画是否反转
//    [UIView setAnimationRepeatAutoreverses:YES];

    [UIView setAnimationBeginsFromCurrentState:YES];
    //旋转
    //2D
    _smallView.transform = CGAffineTransformRotate(_smallView.transform, M_PI_2);

    //缩小
    _smallView.transform = CGAffineTransformScale(_smallView.transform, 2, 2);



    //提交动画
    [UIView commitAnimations];

}

- (IBAction)secondButton:(UIButton *)sender {

    __block ViewController * VC = self;
    [UIView animateWithDuration:1 animations:^{
        //对动画和试图属性进行设置

        [UIView setAnimationRepeatCount:1];

        //视图设置
        //旋转

        VC.smallView.transform = CGAffineTransformRotate(VC.smallView.transform, M_PI_2);

        VC.smallView.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];


    } completion:^(BOOL finished) {

        //可以嵌套,上一个动画执行结束之后,执行的block
        [UIView animateWithDuration:1 animations:^{


            //    改变大小

            VC.smallView.transform = CGAffineTransformScale(_smallView.transform, 0.5, 0.5);

        } completion:^(BOOL finished) {



        }];

    }];
}
- (void)dealloc {
    [_smallView release];
    [super dealloc];
}
#pragma mark ------------UIView的专场动画
- (IBAction)transtimAnimate:(UIButton *)sender {
    __block ViewController *VC = self;
//    
//    [UIView transitionWithView:self.smallView duration:1 options:UIViewAnimationOptionTransitionCurlUp animations:^{
//        
//        //在这个block里,进行动画属性设置
//        
//        [UIView setAnimationRepeatCount:1];
//            
//            VC.smallView.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];//无动画效果
//
//    } completion:^(BOOL finished) {
//        
//    }];

    //两个视图间的转场动画
    UIView * toView = [[UIView alloc]initWithFrame:CGRectMake(80, 300, 100, 100)];
    toView.backgroundColor = [UIColor orangeColor];

    [self.view addSubview:toView];

    [UIView transitionFromView:self.smallView toView:toView duration:1 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {

    }];

    //将self.myView从父视图上移除(销毁掉了),同时将toView添加到父视图上
}
@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值