繁体   English   中英

简单的核心动画运动IOS

[英]Simple core animation movement IOS

以下是一些核心动画的代码,这些动画可以在屏幕加载时移动图像。 它工作正常,但现在还不行。 如果您中的任何一个熟悉核心动画,id就会知道如何使图像不会像下面的代码那样跨屏幕滑动到固定位置。 但只需使其绕自己的轴旋转即可。 效果看起来像是一个矩形,沿其自身的轴连续向右旋转,就像经典的加载动画一样。 任何提示都会有所帮助。 蚂蚁关键词或短语将我指向写作方向。

@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

尝试使用UIView类中的[myView animateWithDuration:animations:] ,并为动画代码块传递一些代码,这些代码将更改视图图层的transform属性以合并旋转。

我对Core Animation不太了解,也不知道这种方法是否可行,但认为您希望获得所有帮助。 希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM