在可视化编程下
#import "BaseViewController.h"
@interface BaseViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation BaseViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
// 改变大小
- (IBAction)changeSizeAction:(UIButton *)sender {
// 开始设置动画
[UIView beginAnimations:@"size" context:nil];
// 动画时长
[UIView setAnimationDuration:2];
// 改变后的图片大小
self.imageView.frame = CGRectMake(50, 80, 200, 200);
// 提交动画,开始播放动画
[UIView commitAnimations];
}
// 改变透明度
- (IBAction)changeAlpha:(UIButton *)sender {
[UIView beginAnimations:@"alpha" context:nil];
[UIView setAnimationDuration:2];
self.imageView.alpha = 0.5;
// 改变背景颜色
self.imageView.backgroundColor = [UIColor cyanColor];
[UIView commitAnimations];
}
// 翻转
- (IBAction)overturnAction:(UIButton *)sender {
// 开始设置动画
[UIView beginAnimations:@"fanzhuan" context:nil];
// 动画时长
[UIView setAnimationDuration:2];
// 设置翻转
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.imageView cache:YES];
// 提交动画,开始播放动画
[UIView commitAnimations];
}
// 旋转
- (IBAction)xuanzhuanAction:(UIButton *)sender {
// 开始设置动画
[UIView beginAnimations:@"xuanzhuan" context:nil];
// 动画时长
[UIView setAnimationDuration:2];
// 设置旋转角度
// 参数1:当前的transform 参数2:旋转弧度
CGAffineTransform transform = CGAffineTransformRotate(self.imageView.transform, M_PI_2);
// 设置旋转
[self.imageView setTransform:transform];
// 提交动画,开始播放动画
[UIView commitAnimations];
}
// 复原
- (IBAction)fuyuanAction:(UIButton *)sender {
// 开始设置动画
[UIView beginAnimations:@"xuanzhuan" context:nil];
// 动画时长
[UIView setAnimationDuration:2];
// 设置旋转角度(0度和180度不变,其它值相反)
// 参数1:当前的transform 参数2:旋转弧度
CGAffineTransform transform = CGAffineTransformInvert(self.imageView.transform);
// 设置旋转
[self.imageView setTransform:transform];
// 提交动画,开始播放动画
[UIView commitAnimations];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end