动画,(UIView上)

  //UIView动画
    //开始动画
    [UIView beginAnimations:nil context:nil];
    
    //运动的时间
    [UIView setAnimationDuration:2.0f];
    //延时启动
    //[UIView setAnimationDelay:2.f];
    
    //速度曲线
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    
    //重复执行
    [UIView setAnimationRepeatAutoreverses:YES];
    //重复执行次数
    [UIView setAnimationRepeatCount:10];
    
    
    //代理
    [UIView setAnimationDelegate:self];
    //开始时候执行
    [UIView setAnimationWillStartSelector:@selector(start)];
    //结束的时候执行
    [UIView setAnimationDidStopSelector:@selector(stop)];
    
    
    //动画过程
    //换背景色
    self.myView.backgroundColor=[UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
    //改位置
    CGRect myFrame=self.myView.frame;
    //全局变量
    static BOOL a =YES;
    if (a) {
        myFrame.origin.y+=100;
        myFrame.size.width+=50;
        a=NO;
    }
    else{
        myFrame.origin.y-=100;
        myFrame.size.width-=50;
        a=YES;
    }
    self.myView.frame=myFrame;
    //改变透明度
    
    //self.myView.alpha=0.1;
  
    //提交动画
    [UIView commitAnimations];
    


block块执行

第一种

//系统自带的block块
    [UIView animateWithDuration:2.0f animations:^{
        self.myView.backgroundColor=[UIColor purpleColor];
        
    }];
第二种
/第一个block块执行了动画,
    //第二个block块是在执行完动画后执行的
    [UIView animateWithDuration:2.f animations:^{
        self.myView.backgroundColor=[UIColor greenColor];
    } completion:^(BOOL finished) {
        self.myView.backgroundColor=[UIColor redColor];
    }];

第三种

[UIView transitionWithView:self.myView duration:2.f options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        NSLog(@"动画开始");
    } completion:^(BOOL finished) {
        NSLog(@"动画结束");
    }];

旋转

[UIView animateWithDuration:2.0f animations:^{
//        self.myView.transform=CGAffineTransformScale(self.myView.transform, 0.5f, 0.5f);
        self.myView.transform=CGAffineTransformRotate(self.myView.transform, M_PI_4);
    }];



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值