gpt4 book ai didi

ios - bezierPath moveToPoint 坐标系错误

转载 作者:行者123 更新时间:2023-11-29 02:31:08 24 4
gpt4 key购买 nike

我正在尝试沿任意路径为按钮设置动画。为此,我需要创建一个路径,我正在使用 BezierPath。

但是,每当我将 moveToPoint 设置为 0,0 而不是从屏幕左上角开始动画时,就会发生一些奇怪的事情,按钮会出现在顶部和左侧,因此它只是部分可见。

这里发生了什么? moveToPoint 是否使用其他坐标系?

按钮的 anchor 设置为标准的左上角。

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
bezierPath = [[UIBezierPath alloc]init];
[bezierPath moveToPoint:CGPointMake(0, 0)];
[bezierPath addLineToPoint:CGPointMake(52, 83)];
[bezierPath addLineToPoint:CGPointMake(45, 59)];
[bezierPath addLineToPoint:CGPointMake(65, 30)];
}

-(void)randomAnimation
{
CAKeyframeAnimation* keyframeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
keyframeAnimation.duration = 4.0;
keyframeAnimation.path = [bezierPath CGPath];
[self.rndBtn.layer addAnimation:keyframeAnimation forKey:@"position"];
}

最佳答案

您正在为图层的位置属性设置动画,该属性默认设置为图层的中心。如果您将按钮层的中心设置为 0,0,它将在屏幕边缘居中,并且半关闭。

需要设置起点为width/2,height/2。或者,您可以移动图层的 anchor ,但这会产生副作用。

关于ios - bezierPath moveToPoint 坐标系错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26864546/

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