//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);
}];