作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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];
}
最佳答案
你让这件事变得比它需要的更难。关于 removedOnCompletion
和 removeAnimationForKey:
的内容是伪造的。只需在触摸开始时为缩放变换制作动画,并在触摸结束时制作回识别变换的动画。
(您甚至不需要使用 CABasicAnimation;一个简单的 UIView 动画就可以了——除非您使用自动布局,在这种情况下 CABasicAnimation 更好。)
关于ios - 移除时反转 CABasicAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22997346/
我正在做一个项目,我的 android 在这个项目中作为一个网络服务器工作;输入带端口号的 IP 地址,打开 Web 界面,用户可以将文件上传到手机。我想在 Web 界面上显示一些图片,以便我们的界面
我是一名优秀的程序员,十分优秀!