iOS 簡單動畫主要分爲三種(這是我的理解):
第一種:改變位置,大小等
- //開始動畫
- [UIView beginAnimations:nil context:nil];
- //設定動畫持續時間
- [UIView setAnimationDuration:2];
- //動畫的內容
- frame.origin.x += 150;
- [img setFrame:frame];
- //動畫結束
- [UIView commitAnimations];
- [UIView beginAnimations:@"animation" context:nil];
- [UIView setAnimationDuration:0.6f];
- [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDelegate:self];
- [UIView setAnimationDidStopSelector:@selector(animationDidStop)];
- [UIView setAnimationRepeatAutoreverses:NO];
- [self.view addSubview:self.currentView];
- [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.navigationController.view cache:YES];
- [UIView commitAnimations];
就是上圖的第一排4個按鈕展現的動畫
- CATransition *transition = [CATransition animation];
- transition.duration = 0.4;
- transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- transition.type = kCATransitionPush;
- transition.subtype = kCATransitionFromRight;
- [fromView.layer addAnimation:transition forKey:nil];
CATransition動畫分爲4種,
1、kCATransitionFade;
2、kCATransitionPush;
3、kCATransitionReveal;
4、kCATransitionMoveIn;
後三種又可以選擇4個方向,kCATransitionFromLeft 、kCATransitionFromBottom 、kCATransitionFromRight 、kCATransitionFromTop- + (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
- + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
- + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0, completion = NULL
- + (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
- + (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // toView added to fromView.superview, fromView removed from its superview
- [UIView animateWithDuration:0.6 animations:^{
- self.currentView.frame = CGRectMake(30, 30, 200, 300);
- }];
- [UIView transitionFromView:self.mapviewContainer toView:self.listContainer duration:0.75 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished){
- }];
就是上圖的下面8個按鈕展現的動畫