1. 图片 旋转,缩放,移动可以用 transform 属性
常用的创建transform结构体方法分两大类
(1) 创建“基于控件初始位置”的形变
CGAffineTransformMakeTranslation(平移)
CGAffineTransformMakeScale(缩放)
CGAffineTransformMakeRotation(旋转)
(2) 创建“基于transform参数”的形变
CGAffineTransformTranslate
CGAffineTransformScale
CGAffineTransformRotate
-(void)aa{ [UIView beginAnimations:@"" context:nil]; [UIView setAnimationDuration:2]; imv.transform=CGAffineTransformMakeRotation(20*3.14/180); [UIView commitAnimations]; [self performSelector:@selector(ab) withObject:self afterDelay:5]; label.text=@"向右转"; }-(void)ab{ [UIView beginAnimations:@"" context:nil]; [UIView setAnimationDuration:2]; imv.transform=CGAffineTransformMakeRotation(0); [UIView commitAnimations]; [self performSelector:@selector(ac) withObject:self afterDelay:5]; label.text=@"向左转";}-(void)ac{ [UIView beginAnimations:@"" context:nil]; [UIView setAnimationDuration:2]; imv.transform=CGAffineTransformMakeRotation(-20*3.14/180); [UIView commitAnimations]; [self performSelector:@selector(ad) withObject:self afterDelay:5]; label.text=@"向左转"; }-(void)ad{ [UIView beginAnimations:@"" context:nil]; [UIView setAnimationDuration:2]; imv.transform=CGAffineTransformMakeRotation(0); [UIView commitAnimations]; [self performSelector:@selector(aa) withObject:self afterDelay:5]; label.text=@"向右转"; }
上面的几个方法可以实现 钟摆的效果 摆动
- (IBAction)right:(id)sender {
CGRect f=[iv2frame];
iv2.frame=f;
if(x<=320){
iv2.transform=CGAffineTransformMakeTranslation(x,y);
x+=10;
}
}
if(i>=0.2){
iv2.transform=CGAffineTransformMakeScale(i,i);
}
i-=0.1;
}