我正在尝试在 UISegmentedControl 中对图像进行动画处理。这是我想出来的,但行不通。
如果我在最后一行代码中将 imageView.layer 切换到 _segmentedControl.layer,动画本身就可以正常工作。
我错过了什么?
UIImageView *imageView = [[UIImageView alloc] init];
imageView.image = [_segmentedControl imageForSegmentAtIndex:0];
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scale.duration = 0.25;
scale.repeatCount = 2;
scale.autoreverses = YES;
scale.fromValue = [NSNumber numberWithFloat:1.0];
scale.toValue = [NSNumber numberWithFloat:0.0];
[imageView.layer addAnimation:scale forKey:@"scale"];
最佳答案
为了供将来引用,我想分享我想出的解决方案。您至少可以为分段控件的 subview 设置动画,而不是为分段的图像设置动画(这似乎不可能)。
UIView *subView = [[_segmentedControl subviews] objectAtIndex:0];
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
scale.duration = 0.25;
scale.repeatCount = 1;
scale.autoreverses = YES;
scale.fromValue = [NSNumber numberWithFloat:1.0];
scale.toValue = [NSNumber numberWithFloat:0.95];
[subView.layer addAnimation:scale forKey:@"scale"];
关于ios - 对 UISegmentedControl 图像进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19751960/