//360度转动动画
-(void)rotate360DegreeWithImageView:(UIView *)view{
CABasicAnimation *animation = [CABasicAnimation
animationWithKeyPath: @"transform" ];
//围绕Z轴旋转,垂直与屏幕
animation.fromValue = [NSValue valueWithCATransform3D:
CATransform3DMakeRotation(M_PI,0.0, 0.0, 1.0) ];
animation.toValue = [NSValuevalueWithCATransform3D:CATransform3DIdentity];
animation.duration =0.3;
//旋转效果累计,先转180度,接着再旋转180度,从而实现360旋转
animation.cumulative =YES;
animation.repeatCount =1000;
[view.layeraddAnimation:animation forKey:nil];
}
//停止转动-(void)stopAnimate:(UIView *)view
{
[view.layerremoveAllAnimations];
}
//放大缩小的动画
- (void) shakeToShow:(UIView*)aView{
CAKeyframeAnimation* animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform"];
animation.duration =0.5;
NSMutableArray *values = [NSMutableArrayarray];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.1,0.1, 1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.05,1.05, 1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(0.95,0.95, 1.0)]];
[values addObject:[NSValuevalueWithCATransform3D:CATransform3DMakeScale(1.0,1.0, 1.0)]];
animation.values = values;
[aView.layeraddAnimation:animation forKey:nil];
}
//左右抖动动画
-(void)lockAnimationForView:(UIView*)view
{
CALayer *layer = [view layer];
CGPoint point = [layer position];
CGPoint y = CGPointMake(point.x-3.5, point.y);
CGPoint x = CGPointMake(point.x+3.5, point.y);
CABasicAnimation * animation = [CABasicAnimationanimationWithKeyPath:@"position"];
[animation setTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animation setFromValue:[NSValuevalueWithCGPoint:x]];
[animation setToValue:[NSValuevalueWithCGPoint:y]];
[animationsetAutoreverses:YES];
[animationsetDuration:0.08];
[animationsetRepeatCount:2];
[layeraddAnimation:animation forKey:nil];
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
//
视图转动动画+
(void)shakeView:(UIView
*)view
duration:(CGFloat)fDuration{ if
(view && (fDuration >= 0.1f)) { CABasicAnimation*
shake = [CABasicAnimation
animationWithKeyPath:@"transform.rotation.z"]; //设置抖动幅度 shake.fromValue
= [NSNumber
numberWithFloat:-0.3]; shake.toValue
= [NSNumber
numberWithFloat:+0.3]; shake.duration
= 0.1f; shake.repeatCount
= fDuration/4/0.1f; shake.autoreverses
= YES; [view.layer
addAnimation:shake
forKey:@"shakeView"]; }else{}}
CAKeyframeAnimation*
anim=[CAKeyframeAnimation
animation]; anim.keyPath=@"transform.rotation"; anim.values=@[@(angelToRandian(-7)),@(angelToRandian(7)),@(angelToRandian(-7))]; anim.repeatCount=MAXFLOAT; anim.duration=0.2; [self.imageView.layer
addAnimation:anim
forKey:nil]; |
本文介绍了iOS开发中实现360度旋转动画、放大缩小动画、左右抖动动画的方法,以及如何通过代码控制这些动画的播放与停止,提供丰富的视图交互体验。
251

被折叠的 条评论
为什么被折叠?



