[ios開発基礎知識の]画面では基本アニメーションがよく使われます。


この記事のソース:http://www.cnblogs.com/v2m_/archive/2011/10/28/2227979.html
一.基本的な方法:UID View類のUID View Animation拡張関数を使って説明する。
+ (void)beginAnimations:(NSString *)animationID context:(void *)context; //       
+ (void)commitAnimations; //     

//   get  ,   set       
+ (void)setAnimationDelegate:(id)delegate; //   default = nil
+ (void)setAnimationWillStartSelector:(SEL)selector; // default = NULL. -animationWillStart:(NSString *)animationID context:(void *)context
+ (void)setAnimationDidStopSelector:(SEL)selector; // default = NULL. -animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
+ (void)setAnimationDuration:(NSTimeInterval)duration; // default = 0.2    
+ (void)setAnimationDelay:(NSTimeInterval)delay; // default = 0.0            
+ (void)setAnimationStartDate:(NSDate *)startDate; // default = now ([NSDate date])      ?     .- -
+ (void)setAnimationCurve:(UIViewAnimationCurve)curve; // default = UIViewAnimationCurveEaseInOut    
+ (void)setAnimationRepeatCount:(float)repeatCount; // default = 0.0. May be fractional    
+ (void)setAnimationRepeatAutoreverses:(BOOL)repeatAutoreverses; // default = NO. YES  ,  (     )             
+ (void)setAnimationBeginsFromCurrentState:(BOOL)fromCurrentState; // default = NO. YES,       ,          the current view position is always used for new animations -- allowing animations to "pile up" on each other. Otherwise, the last end state is used for the animation (the default).

+ (void)setAnimationTransition:(UIViewAnimationTransition)transition forView:(UIView *)view cache:(BOOL)cache; //      view ,cache YES       ,                 ,NO        ,      
+ (void)setAnimationsEnabled:(BOOL)enabled; //           
+ (BOOL)areAnimationsEnabled;
アニメーションのコード
- (void)testAnimation{
	int index = 102;
	UIViewAnimationTransition transition = UIViewAnimationOptionTransitionNone;
    switch (index) {
        case 101:
            transition = UIViewAnimationTransitionCurlDown;
            break;
        case 102:
            transition = UIViewAnimationTransitionCurlUp;
            break;
        case 103:
            transition = UIViewAnimationTransitionFlipFromLeft;
            break;
        case 104:
            transition = UIViewAnimationTransitionFlipFromRight;
            break;
        default:
            break;
    }
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationTransition:transition forView:self.view cache:YES];
    
    // operation>>>
	//    [self.view bringSubviewToFront:mImage];
	//    [self.view sendSubviewToBack:mImage];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
	
    // end<<<<<<
    [UIView commitAnimations];	
}
その中のtransionの取得範囲
typedef enum {
UIViewAnimationTransitionNone,
UIViewAnimationTransitionFlipFromLeft,
UIViewAnimationTransitionFlipFromRight,
UIViewAnimationTransitionCurlUp,
UIViewAnimationTransitionCurlDown,
} UIViewAnimationTransition;
: に いやすいですが、 は られています。2.block :UID View を したUIVew Animation WithBlocks
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);//  ,  ,    (    ?),     ,   

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // delay = 0.0, options = 0

+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_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 __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0);

+ (void)transitionFromView:(UIView *)fromView toView:(UIView *)toView duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options completion:(void (^)(BOOL finished))completion __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_0); // toView added to fromView.superview, fromView removed from its superview    ,   options    
[UIView animateWithDuration:0.7 delay:0 options:0 animations:^(void){
		self.view.alpha = 0.2;
		[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
		self.view.alpha = 1;
	} completion:^(BOOL finished)
	 {
		 
	 }];
エリアAnimationEnbaledがNOの 、 の は されません。
{
        UIViewAnimationOptions options = UIViewAnimationOptionTransitionNone;
        switch (((UIButton*)sender).tag) {
            case 202:
                options = UIViewAnimationOptionTransitionCrossDissolve;
                break;
            case 203:
                options = UIViewAnimationOptionTransitionFlipFromTop;
                break;
            case 204:
                options = UIViewAnimationOptionTransitionFlipFromBottom;
                break;
            default:
                break;
        }

        [self.view bringSubviewToFront:lImage];
        [UIView transitionFromView:lImage toView:mImage duration:0.7 options:options completion:^(BOOL finished)
         {
             if (finished) {
                 [self.view addSubview:lImage];
                 [self.view sendSubviewToBack:lImage];
                 [self.view sendSubviewToBack:mImage];
             } 
         }];
    }

options


enum {
UIViewAnimationOptionLayoutSubviews = 1 << 0,
UIViewAnimationOptionAllowUserInteraction = 1 << 1, // turn on user interaction while animating
UIViewAnimationOptionBeginFromCurrentState = 1 << 2, // start all views from current value, not initial value
UIViewAnimationOptionRepeat = 1 << 3, // repeat animation indefinitely
UIViewAnimationOptionAutoreverse = 1 << 4, // if repeat, run animation back and forth
UIViewAnimationOptionOverrideInheritedDuration = 1 << 5, // ignore nested duration
UIViewAnimationOptionOverrideInheritedCurve = 1 << 6, // ignore nested curve
UIViewAnimationOptionAllowAnimatedContent = 1 << 7, // animate contents (applies to transitions only)
UIViewAnimationOptionShowHideTransitionViews = 1 << 8, // flip to/from hidden state instead of adding/removing

UIViewAnimationOptionCurveEaseInOut = 0 << 16, // default
UIViewAnimationOptionCurveEaseIn = 1 << 16,
UIViewAnimationOptionCurveEaseOut = 2 << 16,
UIViewAnimationOptionCurveLinear = 3 << 16,

UIViewAnimationOptionTransitionNone = 0 << 20, // default
UIViewAnimationOptionTransitionFlipFromLeft = 1 << 20,
UIViewAnimationOptionTransitionFlipFromRight = 2 << 20,
UIViewAnimationOptionTransitionCurlUp = 3 << 20,
UIViewAnimationOptionTransitionCurlDown = 4 << 20,
UIViewAnimationOptionTransitionCrossDissolve = 5 << 20,//ios5
UIViewAnimationOptionTransitionFlipFromTop = 6 << 20,//ios5
UIViewAnimationOptionTransitionFlipFromBottom = 7 << 20,//ios5
};
typedef NSUInteger UIViewAnimationOptions;

: , . 1

.core : CATransition
QuartzCore.framework
:ViewTransitions


CATransition *transition = [CATransition animation];
transition.duration = 0.7;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;//{kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};

//    {@"cube",@"suckEffect",@"oglFlip",@"rippleEffect",@"pageCurl",@"pageUnCurl",@"cameraIrisHollowOpen",@"cameraIrisHollowClose"};
transition.subtype = kCATransitionFromLeft;//{kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};

transition.delegate = self;
[self.view.layer addAnimation:transition forKey:nil];

//    
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];

NavigationController push pop , , 。

 [self.navigationController.view.layer addAnimation:transition forKey:nil];



: ( ) , , , , performSelector: withObject: afterDelay: .

: ( ), UIViewController

demo:animations.zip