gpt4 book ai didi

ios - 移除时反转 CABasicAnimation

转载 作者:行者123 更新时间:2023-11-28 22:10:40 26 4
gpt4 key购买 nike

我正在使用 CABasicAnimation 实例在点击时为 UIControl 的缩放设置动画。功能应该是控件将缩放到 0.9,然后在它仍然被按下时停留在那里,当用户松开他/她的手指时,它会放大回原来的大小。

到目前为止,我已经创建了动画并且它可以完美地工作,直到它将动画恢复到其原始大小为止。我没有创建单独的动画来进行放大,而是简单地删除了原始动画。有没有一种方法可以让这个移除动画,这样它看起来就像控件正在响应触摸而缩小和放大?

- (void)shrinkView {
CABasicAnimation *shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = @(0.9);
shrink.duration = 0.5;
shrink.delegate = self;
shrink.removedOnCompletion = NO;
shrink.fillMode = kCAFillModeForwards;
[self.layer addAnimation:shrink forKey:@"shrink"];
}

- (void)enlargeView {
[self.layer removeAnimationForKey:@"shrink"];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self reduceBackgroundOpacity];
[self shrinkView];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
[self increaseBackgroundOpacity];
[self enlargeView];
}

最佳答案

你让这件事变得比它需要的更难。关于 removedOnCompletionremoveAnimationForKey: 的内容是伪造的。只需在触摸开始时为缩放变换制作动画,并在触摸结束时制作回识别变换的动画。

(您甚至不需要使用 CABasicAnimation;一个简单的 UIView 动画就可以了——除非您使用自动布局,在这种情况下 CABasicAnimation 更好。)

关于ios - 移除时反转 CABasicAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22997346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com