- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将 UIView (self.square) 的缩放属性设置为 10% 的动画:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[UIView animateWithDuration:2
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.square.layer.affineTransform = CGAffineTransformMakeScale(0.1f, 0.1f);
}completion:^(BOOL finished){
}];
[self performSelector:@selector(animationInterrupt) withObject:nil afterDelay:1];
}
我想在中间某处中断动画(例如:通过用户交互),并将动画缩放回 100%:
- (void)animationInterrupt {
[UIView animateWithDuration:1
delay:0.0
options: UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.square.layer.affineTransform = CGAffineTransformMakeScale(1.0f, 1.0f);
}completion:^(BOOL finished){
}];
}
这样的动画输出很奇怪。在某些时刻,它会将 self.square 扩展到 100% 以上:
最佳答案
我发现以下内容有效
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 1.0
target: self
selector:@selector(transform)
userInfo: nil repeats:YES];
[timer fire];
}
transform 函数检查动画是否已经在运行并将 fromvalue 设置为当前值
- (void)transform {
double toValue = 0.1;
if (self.goingUp) toValue = 1.0;
self.goingUp = !self.goingUp;
CATransform3D oldTransform = [(CALayer *)[self.transforemer.layer presentationLayer] transform];
double fromValue = oldTransform.m11;
double duration = toValue - fromValue;
if (fromValue > toValue) duration = fromValue - toValue;
duration *= 2;
CGAffineTransform scaleTransform = CGAffineTransformMakeScale(toValue, toValue);
self.transforemer.transform = scaleTransform;
CABasicAnimation *shrink = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
shrink.toValue = [NSNumber numberWithDouble:toValue];
shrink.fromValue = [NSNumber numberWithDouble:fromValue];
shrink.duration = duration;
shrink.fillMode=kCAFillModeForwards;
shrink.removedOnCompletion=NO;
[self.transforemer.layer addAnimation:shrink forKey:@"transformScale"];
}
此处看到的输出:
只需付出最少的努力,您就可以在您的情况下使用该代码。
关于ios - 动画 transform.scale 与 UIViewAnimationOptionBeginFromCurrentState 不按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26543763/
我正在尝试使用 UIViewAnimationOptionBeginFromCurrentState 实现多阶段动画,以允许用户随意取消动画。动画是在两种尺寸之间连续且循环地动画的 View 。当用户
我正在尝试在收到按钮点击时执行这个基本的 UIView 动画: - (IBAction)buttonPress:(id)sender { self.sampleView.alpha = 0.0
我遇到了一个奇怪的bug(或者我真的很笨……):我想在 MKAnnotationView 中显示自定义标注。我正在做的是添加一个自定义 View 作为 MKAnnotationView 的 subvi
我想将 UIView (self.square) 的缩放属性设置为 10% 的动画: - (void)viewDidAppear:(BOOL)animated { [super viewDid
我是一名优秀的程序员,十分优秀!