gpt4 book ai didi

ios - CAShapeLayer 动画 iOS7 问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:56:31 24 4
gpt4 key购买 nike

我一直在努力解决 iOS7(8、9 效果很好)的动画效果,它涉及将圆角矩形收缩成圆形。获得这样的效果。

Desired Effect

但在 iOS7 上尝试收缩圆圈时出现了一些失真。

Distorted Effect on iOS7

我的 View Controller 非常简单

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

CAShapeLayer *layer = [CAShapeLayer layer];
layer.fillColor = [UIColor blackColor].CGColor;
layer.frame = CGRectMake(100, 100, 100, 100);
layer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 100, 50) cornerRadius:25].CGPath;
self.myLayer = layer;
[self.view.layer addSublayer:layer];

}


- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
animation.values = @[
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 100, 50) cornerRadius:25].CGPath,
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(5, 0, 90, 50) cornerRadius:25].CGPath,
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 0, 80, 50) cornerRadius:25].CGPath,
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(15, 0, 70, 50) cornerRadius:25].CGPath,
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(20, 0, 60, 50) cornerRadius:25].CGPath,
(id)[UIBezierPath bezierPathWithRoundedRect:CGRectMake(25, 0, 50, 50) cornerRadius:25].CGPath,
];

animation.keyTimes = @[@(0),
@(0.18),
@(0.36),
@(0.54),
@(0.72),
@(1),
];

animation.duration = 10;
animation.fillMode = kCAFillModeForwards;
[self.myLayer addAnimation:animation forKey:nil];
self.myLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(25, 0, 50, 50) cornerRadius:25].CGPath;
}

最佳答案

这似乎是 iOS 7 的错误。查看此链接:

http://www.paintcodeapp.com/blogpost/code-for-ios-7-rounded-rectangles

帖子底部有一个分类方法可以解决这个问题。我用你的代码测试了它,它似乎有效!我不得不做一个小改动,那就是替换

CGFloat limitedRadius = MIN(radius, limit);

CGFloat limitedRadius = radius;

这使得角半径变得足够大以创建一个圆。可能值得研究为什么角半径首先受到限制,但我会把它留给你:)

关于ios - CAShapeLayer 动画 iOS7 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33648955/

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