由于图层和图像,我有一个我构建的面具。我想用很少的“跳跃”移动这一层(没有很好的翻译动画)。
问题是每当我移动遮罩层的帧时都会发生动画。我试过调用[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];
答案 0 :(得分:1)
UIView
代替吗?removeFromSuperview
和addSubview
而不只是更改框架?