以下是一些核心动画的代码,可以在屏幕上移动图像。它工作正常,但现在没那么多。如果你们中的任何人都熟悉核心动画,我想知道如何使图像不会在屏幕上滑动到固定位置onload,如下面的代码所示;但只需让它在自己的轴上旋转。效果看起来就像一个矩形在自己的轴上向右旋转,就像经典的加载动画一样。任何提示都会有所帮助。 Ant关键字或短语指向我的写入方向。
@interface ViewController : UIViewController
{
CALayer * layer;
}
@end
@implementation ViewController
- (void)viewDidLoad
{
UIImage *image2 = [[UIImage alloc]initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"flogo@2x"ofType:@"png"]];
layer = [CALayer layer];
layer.contents = (__bridge id)image2.CGImage;
layer.position = CGPointMake ([self view].bounds.size.width /2, [self view].bounds.size.height /3 );
layer.bounds= CGRectMake (100,100,1000,1000);
[[[self view] layer] addSublayer: layer];
layer = [CALayer layer];
layer.position = CGPointMake ([self view].bounds.size.width /2, [self view].bounds.size.height /3 );
layer.bounds= CGRectMake (100,100,1000,1000);
CABasicAnimation * moveAnimation = [CABasicAnimation animationWithKeyPath:@"position.y"];
moveAnimation.duration = 2;
moveAnimation.fromValue = [NSNumber numberWithFloat:layer.position.y];
moveAnimation.toValue = [NSNumber numberWithFloat:layer.position.y + 600];
layer.position = CGPointMake(layer.position.x, layer.position.y +100);
[layer addAnimation:moveAnimation forKey: @"move1"];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
@end
答案 0 :(得分:0)
尝试使用UIView类中的[myView animateWithDuration:animations:]
,并为动画代码块传递一些代码,这些代码会更改视图图层的transform属性以包含旋转。
我对核心动画知之甚少,不知道这是否有效,但想到你想要得到的所有帮助。希望这有帮助!