代码之家  ›  专栏  ›  技术社区  ›  ACBurk

使用核心动画调整和移动uiview(cakeyframeanimation)

  •  6
  • ACBurk  · 技术社区  · 15 年前

    这有可能吗?我可以更改图层的不透明度和位置(中心),但每当我试图更改大小或原点时,它都不起作用。

        CAAnimationGroup* anigroup = [CAAnimationGroup new];
    
        CGMutablePathRef thePath = CGPathCreateMutable();
        CGPathAddRect(thePath, NULL, CGRectMake(0,0, 320, 480));
        CGPathAddRect(thePath, NULL, CGRectMake(location.x - 16,location.y-24, 32, 48));
        CGPathAddRect(thePath, NULL, CGRectMake(190, 20, 32, 48));
    
    
        CAKeyframeAnimation* AniLoc = [CAKeyframeAnimation animationWithKeyPath:@"frame"];
        AniLoc.path = thePath;
        AniLoc.keyTimes= [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f],
                                                 [NSNumber numberWithFloat:0.3f],
                                                 [NSNumber numberWithFloat:1.0f],nil];
        AniLoc.duration = 5;
    
        CFRelease(thePath);
    
        anigroup.animations = [NSArray arrayWithObjects:AniLoc,nil];
        anigroup.duration = 5;
    
        [focusview.layer addAnimation:anigroup forKey:nil];
    
    1 回复  |  直到 15 年前
        1
  •  10
  •   Community CDub    7 年前

    可以同时更改动画中视图或层的大小和位置,但作为动画组,而不是通过从一系列矩形创建路径来更改。

    我提供了一个分组动画的例子,它沿着路径移动视图,同时收缩视图并降低其在我的答案中的不透明度。 here . 这是通过对视图跟随的弯曲路径使用cakeyframeanimation(仅对其位置设置动画),然后使用基本动画调整视图边界的大小来实现的。你也可以在那里使用一个cakeyframeanimation,为你想要的每一个尺寸的关键帧使用多个cgsize,确保在将它们放入一个关键帧的nsarray之前将它们包装在nsvalue中。

    要同时设置两个属性的动画,我将两个动画包装在一个caAnimationGroup中,并将其应用到视图的层。