IOS开发:动画1



#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *currentView;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
/*语法形式:
 [UIView beginAnimations:@“动画的名字 “ context:nil];
 ……..
 [UIView commitAnimations];
 */
//首尾动画
- (IBAction)beginAndEndAnmation:(UIButton *)sender {
    
    [UIView beginAnimations:@"第一个动画" context:nil];
    
    //是否根据最新的状态开始动画
    [UIView setAnimationBeginsFromCurrentState:YES];
    
    //设置延迟几秒开始动画
//    [UIView setAnimationDelay:1.0];
    
    //动画执行时间
    [UIView setAnimationDuration:2.0];
    
    //设置动画翻转
    [UIView setAnimationRepeatAutoreverses:YES];
    //设置翻转次数
    [UIView setAnimationRepeatCount:2];
    //要执行动画开始和结束方法,一定要设置代理
    [UIView setAnimationDelegate:self];
    
    //动画结束执行方法
    [UIView setAnimationDidStopSelector:@selector(endAction)];
    //动画开始执行方法
    [UIView setAnimationWillStartSelector:@selector(startAction)];
    
    //拿到view的中心点
    CGPoint point = self.currentView.center;
    
    //让view向下移动50
    point.y += 50;
    self.currentView.center = point;
    
    //旋转
    self.currentView.transform = CGAffineTransformRotate(self.currentView.transform, M_PI);
    
    //放缩
    self.currentView.transform = CGAffineTransformScale(self.currentView.transform, 0.5, 0.5);
    
    [UIView commitAnimations];
    
}

//结束时执行
-(void)endAction{
    NSLog(@"end");
}

//开始时执行
-(void)startAction{
    NSLog(@"start");
}

//block动画块
- (IBAction)blockAnimation:(UIButton *)sender {
    
    //block动画1
//    [UIView animateWithDuration:2.0f animations:^{
//        //拿到view的中心点
//        CGPoint point = self.currentView.center;
//        
//        //让view向下移动50
//        point.y += 50;
//        self.currentView.center = point;
//
//    }];
    
    //block动画2
//    [UIView animateWithDuration:2.0f animations:^{
//        //拿到view的中心点
//        CGPoint point = self.currentView.center;
//        
//        //让view向下移动50
//        point.y += 50;
//        self.currentView.center = point;
//    } completion:^(BOOL finished) {
//        [UIView animateWithDuration:2.0f animations:^{
//            //拿到view的中心点
//            CGPoint point = self.currentView.center;
//
//            //让view向下移动50
//            point.y -= 50;
//            self.currentView.center = point;
//
//        }];
//    }];
    
    
    //block动画3
//    [UIView animateKeyframesWithDuration:2.0f delay:1.0f options:UIViewKeyframeAnimationOptionRepeat animations:^{
//        //拿到view的中心点
//        CGPoint point = self.currentView.center;
//
//        //让view向下移动50
//        point.y -= 50;
//        self.currentView.center = point;
//        
//    } completion:^(BOOL finished) {
//        NSLog(@"123");
//    }];
    
    //第一个参数 弹簧动画效果(0-1)
    //第四个参数 动画起始速度
    [UIView animateWithDuration:2.0f delay:1.0f usingSpringWithDamping:0.01 initialSpringVelocity:5.0f options:UIViewAnimationOptionRepeat animations:^{
        //拿到view的中心点
        CGPoint point = self.currentView.center;

        //让view向下移动50
        point.y += 50;
        self.currentView.center = point;
    } completion:^(BOOL finished) {
        
    }];
    
}

//转场动画
- (IBAction)translationAnimation:(UIButton *)sender {
    
//    [UIView transitionWithView:self.currentView duration:3 options:UIViewAnimationOptionRepeat animations:^{
//        //拿到view的中心点
//        CGPoint point = self.currentView.center;
//        
//        //让view向下移动50
//        point.y += 50;
//        self.currentView.center = point;
//
//    } completion:^(BOOL finished) {
//        
//    }];
    
    
    UIView * view = [[UIView alloc]init];
    view.backgroundColor = [UIColor yellowColor];
    view.frame = CGRectMake(0, 0, 100, 100);
    [self.view addSubview:view];
    
    //转场后 self.currentView 从父视图移除 toView显示
    [UIView transitionFromView:self.currentView toView:view duration:2.0f options:UIViewAnimationOptionTransitionFlipFromRight completion:^(BOOL finished) {
        
    }];
    
}

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

@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值