/*语法形式:
[UIView beginAnimations:@“动画的名字 “ context:nil];
……..
[UIView commitAnimations];
*/
- (IBAction)beginAndEndAction:(UIButton *)sender {
[UIView beginAnimations:@"第一个动画" context:nil];
// 设置是否根据最新的状态开始动画
[UIView setAnimationBeginsFromCurrentState:YES];
// 动画翻转次数
[UIView setAnimationRepeatCount:5];
// 要执行动画开始和结束方法一定要设置代理
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(endAction)];
[UIView setAnimationWillStartSelector:@selector(startAction)];
// 设置延迟几秒开始动画
// [UIView setAnimationDelay:3.0];
// 动画执行时间
[UIView setAnimationDuration:2.0];
// 拿到view的中心点
// CGPoint point = self.currentView.center;
// 设置动画翻转
[UIView setAnimationRepeatAutoreverses:YES];
// 让View下移动50
// point.y += 50;
// self.currentView.center = point;
// 旋转
self.currentView.transform = CGAffineTransformRotate(self.currentView.transform, M_PI);
// 放缩
self.currentView.transform = CGAffineTransformScale(self.currentView.transform, 0.5, 0.5);
// 结束动画
[UIView commitAnimations];
}
- (void)endAction {
NSLog(@"end");
}
- (void)startAction {
NSLog(@"start");
}
- (IBAction)blockAnimationAction:(UIButton *)sender {
//
// [UIView animateWithDuration:2.0f animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y += 50;
// self.currentView.center = point;
//
//
// }];
// block 里面也可以直接加动画
// [UIView animateWithDuration:2.0f animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y += 50;
// self.currentView.center = point;
//
// } completion:^(BOOL finished) {
//
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:2.0];
// [UIView setAnimationDelegate:self];
// CGPoint point = self.currentView.center;
// point.y -= 50;
// self.currentView.center = point;
// [UIView commitAnimations];
//
//
// }];
//
// }];
// 循环
// [UIView animateKeyframesWithDuration:2.0f delay:1.0f options:UIViewKeyframeAnimationOptionRepeat animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y -= 50;
// self.currentView.center = point;
//
//
// } completion:^(BOOL finished) {
// NSLog(@"123");
// }];
// 第三个参数:弹簧效果 (0-1)
// 第四个参数:动画起始速度
[UIView animateWithDuration:2.0f delay:1.0f usingSpringWithDamping:0.05 initialSpringVelocity:500.0f options:UIViewAnimationOptionRepeat animations:^{
// 拿到view的中心点
CGPoint point = self.currentView.center;
// 让View下移动50
point.y -= 50;
self.currentView.center = point;
} completion:^(BOOL finished) {
}];
}
// 转场动画
- (IBAction)translationAction:(UIButton *)sender {
// [UIView transitionWithView:self.currentView duration:3.0f options:UIViewAnimationOptionRepeat animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y -= 50;
// self.currentView.center = point;
//
// } completion:^(BOOL finished) {
//
// }];
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, 300, 300);
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
// 转场后,self.currentView从父视图移除,toView显示
[UIView transitionFromView:self.currentView toView:view duration:2.0f options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
}];
}
[UIView beginAnimations:@“动画的名字 “ context:nil];
……..
[UIView commitAnimations];
*/
- (IBAction)beginAndEndAction:(UIButton *)sender {
[UIView beginAnimations:@"第一个动画" context:nil];
// 设置是否根据最新的状态开始动画
[UIView setAnimationBeginsFromCurrentState:YES];
// 动画翻转次数
[UIView setAnimationRepeatCount:5];
// 要执行动画开始和结束方法一定要设置代理
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(endAction)];
[UIView setAnimationWillStartSelector:@selector(startAction)];
// 设置延迟几秒开始动画
// [UIView setAnimationDelay:3.0];
// 动画执行时间
[UIView setAnimationDuration:2.0];
// 拿到view的中心点
// CGPoint point = self.currentView.center;
// 设置动画翻转
[UIView setAnimationRepeatAutoreverses:YES];
// 让View下移动50
// point.y += 50;
// self.currentView.center = point;
// 旋转
self.currentView.transform = CGAffineTransformRotate(self.currentView.transform, M_PI);
// 放缩
self.currentView.transform = CGAffineTransformScale(self.currentView.transform, 0.5, 0.5);
// 结束动画
[UIView commitAnimations];
}
- (void)endAction {
NSLog(@"end");
}
- (void)startAction {
NSLog(@"start");
}
- (IBAction)blockAnimationAction:(UIButton *)sender {
//
// [UIView animateWithDuration:2.0f animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y += 50;
// self.currentView.center = point;
//
//
// }];
// block 里面也可以直接加动画
// [UIView animateWithDuration:2.0f animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y += 50;
// self.currentView.center = point;
//
// } completion:^(BOOL finished) {
//
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:2.0];
// [UIView setAnimationDelegate:self];
// CGPoint point = self.currentView.center;
// point.y -= 50;
// self.currentView.center = point;
// [UIView commitAnimations];
//
//
// }];
//
// }];
// 循环
// [UIView animateKeyframesWithDuration:2.0f delay:1.0f options:UIViewKeyframeAnimationOptionRepeat animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y -= 50;
// self.currentView.center = point;
//
//
// } completion:^(BOOL finished) {
// NSLog(@"123");
// }];
// 第三个参数:弹簧效果 (0-1)
// 第四个参数:动画起始速度
[UIView animateWithDuration:2.0f delay:1.0f usingSpringWithDamping:0.05 initialSpringVelocity:500.0f options:UIViewAnimationOptionRepeat animations:^{
// 拿到view的中心点
CGPoint point = self.currentView.center;
// 让View下移动50
point.y -= 50;
self.currentView.center = point;
} completion:^(BOOL finished) {
}];
}
// 转场动画
- (IBAction)translationAction:(UIButton *)sender {
// [UIView transitionWithView:self.currentView duration:3.0f options:UIViewAnimationOptionRepeat animations:^{
//
// // 拿到view的中心点
// CGPoint point = self.currentView.center;
//
// // 让View下移动50
// point.y -= 50;
// self.currentView.center = point;
//
// } completion:^(BOOL finished) {
//
// }];
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, 0, 300, 300);
view.backgroundColor = [UIColor redColor];
[self.view addSubview:view];
// 转场后,self.currentView从父视图移除,toView显示
[UIView transitionFromView:self.currentView toView:view duration:2.0f options:UIViewAnimationOptionTransitionCrossDissolve completion:^(BOOL finished) {
}];
}