@interface HomeViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *myView;
- (IBAction)startAnimation:(UIButton *)sender;
@property (weak, nonatomic) IBOutlet UIView *parentView;
- (IBAction)transitionAction:(UIButton *)sender;
@end
@implementation HomeViewController
- (IBAction)startAnimation:(UIButton *)sender {
// [UIView beginAnimations:@"testAnimation" context:nil]; //设置动画名称
// [UIView setAnimationDuration:0.5];//设置动画时长
// //默认动画效果
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
// [UIView setAnimationDelegate:self]; //设置代理
// [UIView setAnimationDidStopSelector:@selector(animationStop)];
//
// CGRect frame = self.myView.frame;
// frame.origin.y = 500;
//
// self.myView.frame = frame;
//
// [UIView commitAnimations];//动画结束
//透明度
self.view.alpha =1;
//缩放
self.myView.transform = CGAffineTransformScale(self.myView.transform,1,1);
//block方法
[UIViewanimateWithDuration:0.7animations:^{
//改变Y轴位置
// CGRect frame = self.myView.frame;
// frame.origin.y += 400;
// self.myView.frame = frame;
//设置动画重复执行
[UIViewsetAnimationRepeatCount:1000];
//改变透明度
self.view.alpha =0.1;
//大小缩放,不能设值为0,可以设一个很小的数
self.myView.transform =CGAffineTransformScale(self.myView.transform,0.01, 0.01);
}completion:^(BOOL finished){
if (finished) {
[UIViewanimateWithDuration:0.7animations:^{
// CGRect frame = self.myView.frame;
// frame.origin.y -= 400;
// self.myView.frame = frame;
self.view.alpha =1;
//恢复原始大小
self.myView.transform =CGAffineTransformIdentity;
}];
}
}];
}
//-(void)animationStop{
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:0.5];
// CGRect frame = self.myView.frame;
// frame.origin.y -= 300;
// self.myView.frame = frame;
// [UIView commitAnimations];
//}
- (IBAction)transitionAction:(UIButton *)sender {
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:1];
// //设置动画样式
// [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.parentView cache:YES];
// [UIView commitAnimations];
//视图索引变换
[self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
//
//block方法
[UIView transitionWithView:self.parentView duration:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
//[self.parentView exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
} completion:NULL];
}
@end