一.UIViewAnimation实例:Animation块动画,Animation块支持多种动画叠加,会产生各种不同的效果
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDelegate:delegate];
[UIView setAnimationWillStartSelector:startSelector];//开始的代理
[UIView setAnimationDidStopSelector:stopSelector];//结束的代理
[UIView setAnimationDuration:seconds];
//改变后的参数,动画将会从初始化的参数向改变后的参数过渡
//位置:
tempView.center = center;
//大小transform
tempView.transform = CGAffineTransformMakeScale(number, number);
//透明度
tempView.alpha = 0;
//旋转
CGAffineTransform newTransform = CGAffineTransformMakeRotation(M_PI);
[viewToAddAnimation setTransform:newTransform];
//翻转两个View的动画:
把一个removeFromSupview同时把另一个addSubView,设置一下动画的翻转效果:上下左右选一个;
[view1 removeFromSupview];
[view addSubView:view2];
//横向滑动效果等
[UIView commitAnimations];
.........
二.CAAnimation实例:
+(void) showCustemAlertViewInRect:(CGRect) frame inView:(UIView *) superview
{
UIView *tempView = [UIGloble newWhiteViewWithFrame:frame backgroundColor:[UIColor blueColor]];
[superview addSubview:tempView];//CGRectMake(40, 60, DeviceWidth-80, DeviceHeight-200)
CAKeyframeAnimation *animation=nil;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.8;
animation.delegate = self;
animation.removedOnCompletion = YES;
animation.fillMode = kCAFillModeForwards;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[tempView.layer addAnimation:animation forKey:nil];
[tempView release];
}
CALayer*viewLayer=[self layer];
CABasicAnimation*animation=[CABasicAnimation animationWithKeyPath:@"transform"];
animation.duration=0.2;
animation.repeatCount = 100000;
animation.autoreverses=YES;
animation.fromValue=[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform, -0.03, 0.0, 0.0, 0.03)];
animation.toValue=[NSValue valueWithCATransform3D:CATransform3DRotate(viewLayer.transform, 0.03, 0.0, 0.0, 0.03)];
[viewLayer addAnimation:animation forKey:@"wiggle"];
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; [animation setDuration:0.8]; CGPoint p1 = tempButton.center; CGPoint p2 = CGPointMake(152, 97); CGPoint p3 = CGPointMake(189, 110); CGPoint p4 = CGPointMake(220, 124); CGPoint p5 = CGPointMake(245, 163); CGPoint p6 = CGPointMake(220, 250); CGPoint p7 = CGPointMake(177, 379); [animation setValues:[NSArray arrayWithObjects: [NSValue valueWithCGPoint:p1], [NSValue valueWithCGPoint:p2], [NSValue valueWithCGPoint:p3], [NSValue valueWithCGPoint:p4], [NSValue valueWithCGPoint:p5], [NSValue valueWithCGPoint:p6], [NSValue valueWithCGPoint:p7], nil]]; [animation setKeyTimes:[NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.3], [NSNumber numberWithFloat:0.4], [NSNumber numberWithFloat:0.5], [NSNumber numberWithFloat:0.6], [NSNumber numberWithFloat:0.7], [NSNumber numberWithFloat:0.8], nil]]; //[animation setAutoreverses:YES];//返回到原始状态 [tempButton.layer addAnimation:animation forKey:@"BookView-Fly"]; [UIGloble addAnimationFade:tempButton duraion:0.8]; [UIGloble addAnimationScal:tempButton toPoint:tempButton.center lightState:YES delegate:tempButton startSelector:nilstopSelector:@selector(removeFromSuperview) scaleNumber:0.1 duraion:0.8]; [tempButton release]; [self performSelector:@selector(changeBadgeValue) withObject:nil afterDelay:0.8]; 六.CATransition,cube动画翻转,privateAPI CATransition *animation = [CATransition animation]; animation.delegate = self; animation.duration = 0.5f; animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = kCAFillModeRemoved;
// Curl the image up or down CATransition *animation = [CATransition animation]; [animation setDuration:0.35]; [animation setTimingFunction:UIViewAnimationCurveEaseInOut]; if (!curled){ //animation.type = @"mapCurl"; animation.type = @"pageCurl"; animation.fillMode = kCAFillModeForwards; animation.endProgress = 0.99; } else { //animation.type = @"mapUnCurl"; animation.type = @"pageUnCurl"; animation.fillMode = kCAFillModeBackwards; }
animation.removedOnCompletion = NO;animation.type = @"cube";[[UIApplication sharedApplication].keyWindow.layer addAnimation:animation forKey:@"animationID"];
[UIView beginAnimations:@"Curl"context:nil];//动画开始
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:myview cache:YES];
[myview removeFromSuperview];
[UIView commitAnimations];
CATransition *animation = [CATransition animation];
[animation setDuration:1.25f];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn]];
[animation setType:kCATransitionReveal];
[animation setSubtype: kCATransitionFromBottom];
[self.view.layer addAnimation:animation forKey:@"Reveal"];
// Curl the image up or down
CATransition *animation = [CATransition animation];
[animation setDuration:0.35];
[animation setTimingFunction:UIViewAnimationCurveEaseInOut];
if (!curled){
//animation.type = @"mapCurl";
animation.type = @"pageCurl";
animation.fillMode = kCAFillModeForwards;
animation.endProgress = 0.99;
}
else {
//animation.type = @"mapUnCurl";
animation.type = @"pageUnCurl";
animation.fillMode = kCAFillModeBackwards;
}
| |