iphone - 不想删除的图层上的动画

标签 iphone ios core-animation calayer mask

我有一个通过图层和图像构建的蒙版。我想用一点“跳跃”来移动这一层(没有漂亮的翻译动画)。

问题是每当我移动 mask 层的框架时就会发生动画。我尝试调用 [maskLayer removeAllAnimations]; 但它没有改变任何内容。

在我的代码中,我根本没有放置任何动画,所以我不明白这个动画来自哪里。

当我启动此功能时:

-(void) moveAlternativeMask:(CALayer*) maskLayer {
     NSLog (@"moveAlternativeMask %@", NSStringFromCGRect(maskLayer.frame));

    // Change the frame of the layer
    CGRect originalFrame = maskLayer.frame;
    CGFloat newYPos = maskLayer.frame.origin.y + 5.;
    maskLayer.frame = CGRectMake (originalFrame.origin.x, newYPos, originalFrame.size.width, originalFrame.size.height);

    // Try removing all animations on the layer
    NSLog (@"Animations");
    for (NSString* animationKey in maskLayer.animationKeys) {
        NSLog(@"    Animation With Key %@", animationKey);
    }
    NSLog (@"End animations");
    [maskLayer removeAllAnimations];

    NSLog (@"Animations after removing");
    for (NSString* animationKey in maskLayer.animationKeys) {
        NSLog(@"    Animation With Key %@", animationKey);
    }
    NSLog (@"End animations after removing");

    // Launch the animation with a small delay
    [self performSelector:@selector(moveAlternativeMask:) withObject:maskLayer afterDelay:0.5];

}

我得到这个日志:

----moveAlternativeMask {{0, 200}, {768, 643}} ---- 动画 带关键点的动画:位置 结束动画 删除后的动画
删除后结束动画

---moveAlternativeMask {{0, 205}, {768, 643}} 动画 带关键点的动画:位置 结束动画 删除后的动画
删除后结束动画

---moveAlternativeMask {{0, 210}, {768, 643}} 动画 带关键点的动画:位置 结束动画 删除后的动画
删除后结束动画

所以图层按照我想要的方式移动,唯一的问题是“位置”动画不断返回......

请注意,CALayer 的构建方式如下:

UIImage *maskImage = [UIImage imageNamed:@"masque2.png"];
self.maskLayer = [CALayer layer];
self.maskLayer.contents = (id) maskImage.CGImage;
self.maskLayer.frame = CGRectMake(0, ORIGINAL_Y_POSITION, 768, 643);
[myView.layer setMask:self.maskLayer];

最佳答案

嗯,很奇怪。我有两个想法:

  1. 尝试使用 UIView 来执行此操作是否可行?
  2. 您是否可以尝试 removeFromSuperviewaddSubview 而不仅仅是更改框架?

关于iphone - 不想删除的图层上的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7311080/

相关文章:

iphone - 通过 XML 从 iPhone 向 App Engine 发送图像

iphone - Cocos2d/Box2d CCRibbon 碰撞检测

ios - 手动动画 UIScrollView.contentOffset 时背景图案跳跃

ios - animationDidStop 方法的多个 CAAnimations?

ios - 我的 IOS 应用程序是否正确设置了我的谷歌分析?

cocoa - 如何旋转 CALayer 支持的 NSView 子类

iphone - iPhone 模拟器音频仅适用于 44100Hz、22050Hz 和 11025Hz

iphone - MapKit - polylineWithCoordinates 互连所有点

iphone - 如何从 NSMutableArray (iPhone) 获取第一个值?

ios - 如何从 Flutter 应用运行 ipa 文件