gpt4 book ai didi

ios - 如何使 CABasicAnimation 在 superLayer 边界之外不可见?

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

我试图将一个三角形从 UIView 边界外移动到 UIView 区域。

我正在使用 UIBezierPath。

当三角形在区域之外时,我希望它不可见。我只希望 UIView 内的三角形部分可见。

不幸的是,它在整个动画中都是可见的(在边界外和边界内)。

这是我的代码:

UIBezierPath *triangle = [UIBezierPath bezierPath];
[triangle moveToPoint:CGPointMake(X, Y)];
[triangle addLineToPoint:CGPointMake(X - (width*0.5), Y)];
[triangle addLineToPoint:CGPointMake(X, Y + (width*0.5))];
[triangle closePath];
CAShapeLayer *triLayer = [CAShapeLayer layer];
triLayer.frame = testView.bounds;
triLayer.path = triangle.CGPath;
triLayer.strokeColor = [[UIColor redColor] CGColor];
triLayer.fillColor = [[UIColor yellowColor] CGColor];

[testView.layer addSublayer:triLayer];

CABasicAnimation *triangleAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];
triangleAnimation.duration=0.5;
triangleAnimation.repeatCount=1;
triangleAnimation.autoreverses=NO;

triangleAnimation.fromValue=[NSNumber numberWithFloat:(width*0.5)];
triangleAnimation.toValue=[NSNumber numberWithFloat:0];
triangleAnimation.removedOnCompletion = NO;
triangleAnimation.fillMode = kCAFillModeForwards;

[triLayer addAnimation:triangleAnimation forKey:@"animateLayer"];

最佳答案

如果您有对 super View 本身的引用,您可以将其上的 clipsToBounds 属性设置为 YES。否则,您可以使用 CALayermasksToBounds 属性来做同样的事情。

关于ios - 如何使 CABasicAnimation 在 superLayer 边界之外不可见?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15694163/

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