我想旋轉圓形動畫中的圖像。我怎樣才能以簡單的方式做到這一點? 我知道這並不難,但我是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