gpt4 book ai didi

uikit - CAShapeLayer 缓慢的用户交互

转载 作者:行者123 更新时间:2023-12-03 18:24:19 24 4
gpt4 key购买 nike

我有一个 CAShapeLayer,它必须在用户手指的引导下完成在屏幕上移动的简单任务。

问题是 Action 太慢了。图层确实移动了,但有延迟,感觉很慢。

我有另一个测试应用程序,其中 UIImage 被移动并且完全没有延迟并且图像立即移动。

我能做些什么来克服这个问题?

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

currentPoint = [[touches anyObject] locationInView:self];

}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{

CGPoint activePoint = [[touches anyObject] locationInView:self];
CGPoint newPoint = CGPointMake(activePoint.x - currentPoint.x,activePoint.y - currentPoint.y);
curLayer.position = CGPointMake(shapeLayer.position.x+newPoint.x,shapeLayer.position.y+newPoint.y);
当前点 = 事件点;

}

谢谢!

最佳答案

请记住,当您在图层上设置位置时(假设它不是默认禁用操作的 UIView 的根图层),它会隐式动画到新位置,这需要 0.25 秒。如果你想让它更快速,请暂时禁用图层上的操作,如下所示:

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint activePoint = [[touches anyObject] locationInView:self];
CGPoint newPoint = CGPointMake(activePoint.x -
currentPoint.x,activePoint.y - currentPoint.y);

[CATransaction begin];
[CATransaction setDisableActions:YES];
curLayer.position = CGPointMake(shapeLayer.position.x +
newPoint.x, shapeLayer.position.y + newPoint.y);
[CATransaction commit];
currentPoint = activePoint;
}

这应该会导致它跳到新位置而不是动画。如果这没有帮助,那么让我看看您的图层初始化代码,以便我可以看到它具有哪些属性和尺寸。例如,cornerRadius 等属性会影响性能。

关于uikit - CAShapeLayer 缓慢的用户交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5010776/

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