我想旋转圆形动画中的图像。我怎样才能以简单的方式做到这一点? 我知道这并不难,但我是iOS新手。 任何人都可以告诉我正确的代码吗?我可以用动画围绕中心旋转UIImage吗?
0
A
回答
1
其我的解决方案:
- (void)startAnimation
{
[UIView animateWithDuration:.4 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
[self.loadingRingImageView setTransform:CGAffineTransformRotate(self.loadingRingImageView.transform, M_SQRT2)];
} completion:^(BOOL finished) {
if (finished)
{
[self startAnimation];
}
}];
}
1
[[self.<imageviewinstance> layer] addAnimation:[self rotationAnimation] forKey:nil];
添加上面的动画,下面是动画代码。
- (CABasicAnimation *)rotationAnimation
{
CABasicAnimation *rotAnim = [CABasicAnimation animationWithKeyPath:@"position"];
[rotAnim setFromValue:[NSValue valueWithCGPoint:CGPointMake(100.0, 400.0)]];
rotAnim.toValue = [NSValue valueWithCGPoint:CGPointMake(300.0, 150.0)];
// rotAnim.duration = 5.0;
rotAnim.autoreverses = YES;
// rotAnim.repeatCount = HUGE_VAL;
rotAnim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
return rotAnim;
}
如果上面没有奏效使用该
- (CABasicAnimation *)rotationAnimation
{
CABasicAnimation *move = [CABasicAnimation animationWithKeyPath:@"transform.rotation" ];
move.delegate = self;
[move setFromValue:[NSNumber numberWithFloat:0]];
[move setToValue:[NSNumber numberWithFloat:50]];
[move setDuration:10.0f];
move.autoreverses = YES;
}
+0
哪里写这个代码? – 2014-09-26 07:22:15
+0
imageviewinstance in [[self。
0
的问题,我想知道的答案是 - >
UIImageView *imageViewForAnimation = [[UIImageView alloc] initWithImage:imageToAnimate];
imageViewForAnimation.alpha = 1.0f;
CGRect imageFrame = imageViewForAnimation.frame;
//Your image frame.origin from where the animation need to get start
CGPoint viewOrigin = imageViewForAnimation.frame.origin;
viewOrigin.y = viewOrigin.y + imageFrame.size.height/2.0f;
viewOrigin.x = viewOrigin.x + imageFrame.size.width/2.0f;
imageViewForAnimation.frame = imageFrame;
imageViewForAnimation.layer.position = viewOrigin;
[self.view addSubview:imageViewForAnimation];
// Set up fade out effect
CABasicAnimation *fadeOutAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadeOutAnimation setToValue:[NSNumber numberWithFloat:0.3]];
fadeOutAnimation.fillMode = kCAFillModeForwards;
fadeOutAnimation.removedOnCompletion = NO;
// Set up scaling
CABasicAnimation *resizeAnimation = [CABasicAnimation animationWithKeyPath:@"bounds.size"];
[resizeAnimation setToValue:[NSValue valueWithCGSize:CGSizeMake(40.0f, imageFrame.size.height * (40.0f/imageFrame.size.width))]];
resizeAnimation.fillMode = kCAFillModeForwards;
resizeAnimation.removedOnCompletion = NO;
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
//Setting Endpoint of the animation
CGPoint endPoint = CGPointMake(480.0f - 30.0f, 40.0f);
//to end animation in last tab use
//CGPoint endPoint = CGPointMake(320-40.0f, 480.0f);
CGMutablePathRef curvedPath = CGPathCreateMutable();
CGPathMoveToPoint(curvedPath, NULL, viewOrigin.x, viewOrigin.y);
CGPathAddCurveToPoint(curvedPath, NULL, endPoint.x, viewOrigin.y, endPoint.x, viewOrigin.y, endPoint.x, endPoint.y);
pathAnimation.path = curvedPath;
CGPathRelease(curvedPath);
CAAnimationGroup *group = [CAAnimationGroup animation];
group.fillMode = kCAFillModeForwards;
group.removedOnCompletion = NO;
[group setAnimations:[NSArray arrayWithObjects:fadeOutAnimation, pathAnimation, resizeAnimation, nil]];
group.duration = 0.7f;
group.delegate = self;
[group setValue:imageViewForAnimation forKey:@"imageViewBeingAnimated"];
[imageViewForAnimation.layer addAnimation:group forKey:@"savingAnimation"];
相关问题
- 1. CALayer围绕中心旋转
- 2. 核心动画:在10.8上设置anchorPoint以围绕其中心旋转一层
- 3. SVG动画围绕中心点旋转路径。
- 4. 使用CIFilter围绕中心旋转CIImage
- 5. CSS动画:围绕X轴旋转?
- 6. 围绕中心点旋转身体
- 7. 围绕中心旋转图像
- 8. 围绕一个中心点旋转CGPoint
- 9. Android - 围绕中心点旋转图像?
- 10. java的旋转矩形围绕中心
- 11. 围绕它的中心旋转图片
- 12. 围绕中心旋转空对象
- 13. 围绕中心旋转按钮
- 14. 围绕中心旋转SVG元素
- 15. Swift:围绕中心点旋转图层
- 16. 在画布中围绕其中心点旋转图像
- 17. 围绕物体旋转相机vs围绕其中心旋转物体
- 18. jQuery和围绕中心点的动画
- 19. 围绕点旋转
- 20. 我可以围绕OS API崩溃吗?
- 21. XNA 4.0 - 围绕自己的轴旋转和围绕世界中心
- 22. 使用CBasicAnimation围绕物体中心旋转的问题
- 23. 围绕Y轴旋转
- 24. 旋转矩形围绕SVG
- 25. 围绕点xna旋转2D
- 26. 围绕轴旋转物体
- 27. 围绕替代轴旋转
- 28. FabricJS围绕X轴旋转
- 29. 围绕一个点旋转
- 30. 在Unity C中围绕中心点旋转#
这个代码中的图像在哪里? – 2014-09-26 07:11:59
我认为它不是正确的解决方案? – 2014-09-26 07:17:46
self.loadingRingImageView is UIImageView – Bimawa 2014-09-26 07:29:03