block动画
[UIView animateWithDuration:1.0 animations:^{
label.alpha = 1.0;
} completion:^(BOOL finished) {
[label removeFromSupperView];
}];
首尾式动画
[UIView beginAnimations:nil context:nil];
[UIView animatewithDuration:2 {
...
})];
[UIView .commitAnimations()];
transform 属性
位移
// 基于对象的初始位置坐的形变
imageView.transform = CGAffineTransformMakeTranslation(0, 20);
// 基于transform参数坐的形变,世纪效果就是一个累加的位移效果
imageView.transform = CGAffineTransformTranslate(self.headImageView.transform, 0, -20);
放大缩小
imageView.transform = CGAffineTransformScale(imageView.transform, 2.0, 1.0);
旋转
// OC中所有跟角度相关的数值,都是弧度值
imageView.transform = CGAffineTransformRotate(imageView, transform, M_PI_4);
帧动画( 汤姆猫)
// 所谓帧动画就是让一组图片一张一张的顺序播放
if ([self.tom isAnimating]) return;
// 图片的数组
NSMutableArray *arrayM = [NSMutableArray array];
for (int i=0; i<81; i++) {
NSString *imageView = [NSString stringWithFormat:@"drink_%02d.jpg", i];
// UIImage *iamge = [UIImage imageNamed: imageName]; // 图片使用后不会直接释放掉,具体释放时间由系统决定
NSString *path = [NSBundle mainBundle] pathForResource:imageName ofType:nil];
UIImage *image = [UIImage iamgeWithContentsOfFile:path];
[arrayM addObject: image];
}
[self.tom setAnimationImages: arrayM];
[self.tom setAnimationDuration:arrayM.count * 0.075];
// 设置动画时长
[self.tom setAnimationRepeatCount: 1];
// 开始动画
[self.tom startAnimating];
// 动画完成后清除图片
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration];