UIView动画

CGContextRef context = UIGraphicsGetCurrentContext();
	[UIView beginAnimations:nil context:context];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	[UIView setAnimationDuration:1.0];
     //使用当前正在运行的动画状态开始下一段动画,避免了因动画状态不一样而产生的跳跃
    [UIView setAnimationBeginsFromCurrentState:YES];
	[[self.view viewWithTag:999] setAlpha:1.0f];
	[UIView commitAnimations];
一,试图的交换:
UIView *frontObject = [[self.view subviews] objectAtIndex:2];
 UIView *backObject = [[self.view subviews] objectAtIndex:1];
 
 CGContextRef context = UIGraphicsGetCurrentContext();
 [UIView beginAnimations:nil context:context];
 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 [UIView setAnimationDuration:1.0];
 
 frontObject.alpha = 0.0f;
 backObject.alpha = 1.0f;
 frontObject.transform = CGAffineTransformMakeScale(0.25f, 0.25f);//缩放的比例
    
 backObject.transform = CGAffineTransformIdentity;//重置视图
 [self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];//交换两个字视图的索引


 [UIView setAnimationDelegate:self];
 [UIView setAnimationDidStopSelector:@selector(animationFinished:)];//动画执行完以后的回调方法
 [UIView commitAnimations];
二,翻转视图
CGContextRef context = UIGraphicsGetCurrentContext();
 [UIView beginAnimations:nil context:context];
 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 [UIView setAnimationDuration:1.0];
 
 UIView *whiteBackdrop = [self.view viewWithTag:100];


 // Choose left or right flip
 if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex])
 [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:whiteBackdrop cache:YES];
 else
 [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:whiteBackdrop cache:YES];


    
    //交换两个视图
 NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];
 NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];
 [whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];


 [UIView setAnimationDelegate:self];
 [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
 [UIView commitAnimations];
三,翻页动画
CGContextRef context = UIGraphicsGetCurrentContext();
 [UIView beginAnimations:nil context:context];
 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
 [UIView setAnimationDuration:1.0];
 
 UIView *whiteBackdrop = [self.view viewWithTag:100];


 // Choose up or down curl
 if ([(UISegmentedControl *)self.navigationItem.titleView selectedSegmentIndex])
 [UIView setAnimationTransition: UIViewAnimationTransitionCurlUp forView:whiteBackdrop cache:YES];
 else
 [UIView setAnimationTransition: UIViewAnimationTransitionCurlDown forView:whiteBackdrop cache:YES];


 NSInteger purple = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:999]];
 NSInteger maroon = [[whiteBackdrop subviews] indexOfObject:[whiteBackdrop viewWithTag:998]];
 [whiteBackdrop exchangeSubviewAtIndex:purple withSubviewAtIndex:maroon];


 [UIView setAnimationDelegate:self];
 [UIView setAnimationDidStopSelector:@selector(animationFinished:)];
 [UIView commitAnimations];
UIViewAnimationTransition的几种效果
    UIViewAnimationTransitionNone,
    UIViewAnimationTransitionFlipFromLeft,//UIView过分,从左向右翻转,用新视图代替旧视图
    UIViewAnimationTransitionFlipFromRight,//UIView过分,从右向左翻转,隐藏旧视图,显示新视图
    UIViewAnimationTransitionCurlUp, //用从下向上翻页盖住旧视图
    UIViewAnimationTransitionCurlDown,//新视图从上向下翻页盖住旧视图
相关文章
相关标签/搜索