我正在开发一个商务应用程序.当我将一个项目添加到购物车时,我想创建一个效果,其中项目的图像遵循弯曲的路径,最终在购物车选项卡上.
如何沿这样的曲线创建图像动画?
对于具有通常的四个点a,b,c和d的三次Bézier曲线,
对于给定值t,
如何最优雅地找到那一点的切线?
我使用该方法制作了四条曲线路径CGPathAddQuadCurveToPoint.我完美地完成了这条道路.但是,我想知道参与路径的所有坐标点.
有没有办法检索路径中的所有坐标点?
如果没有,你有任何其他解决方案用于以数学方式检索曲线中的所有点.
提前谢谢,Vamshi
想象一下,你有一个完全正常的四点贝塞尔曲线(两点和两个控制点)使用curveToPoint创建:controlPoint1:controlPoint2:在你的cocoa应用程序中:
你如何沿曲线找到点(和切线)?
后来:对于基于Michal的答案的完整,简化的解决方案,请点击:
找到立方贝塞尔曲线上的点的切线(在iPhone上)
只需复制并粘贴代码:https://stackoverflow.com/a/31317254/294884
我有一个UIBezierPath(曲线像'8',只有4个点),我需要制作一些CGPoint-Array.有任何想法吗?感谢名单!
编辑:
我有这样的bezier初始化
-(void) initBezier
{
theBezierPath = [UIBezierPath bezierPath];
[theBezierPath moveToPoint:P(211.00, 31.00)];
[theBezierPath addCurveToPoint:P(870.00, 191.00) controlPoint1:P(432.00, -11.00) controlPoint2:P(593.00, 209.00)];
[theBezierPath addCurveToPoint:P(731.00, 28.00) controlPoint1:P(1061.95, 178.53) controlPoint2:P(944.69, 5.78)];
[theBezierPath addCurveToPoint:P(189.00, 190.00) controlPoint1:P(529.00, 49.00) controlPoint2:P(450.00, 189.00)];
[theBezierPath addCurveToPoint:P(211.00, 31.00) controlPoint1:P(-33.01, 190.85) controlPoint2:P(71.00, 37.00)];
}
Run Code Online (Sandbox Code Playgroud)
我用它动画一个物体
anim = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"];
anim.path = theBezierPath.CGPath;
anim.calculationMode = kCAAnimationCubicPaced;
anim.repeatCount = HUGE_VALF;
anim.duration = tme;
Run Code Online (Sandbox Code Playgroud)
我想逐个像素地(通过触摸位置)为路径上的对象设置动画.我希望对象将触摸的给定坐标"捕捉"到曲线上的最近点,以便沿着路径触摸滑动对象.
我使用CAShapeLayer在屏幕上画一条线.在touchesEnded方法中,我想检查"线是否通过该点?".在我的代码中,当我按下屏幕的任何部分时,该方法包含返回始终为true.也许,我在line.frame =(view?.bounds)中遇到了问题!.我该如何解决?对不起,我的英语不好.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
let firstPosition = touch?.location(in: self)
if atPoint(firstPosition!) == lvl1 {
let firstPositionX = firstPosition?.x
let firstPositionY = frame.size.height - (firstPosition?.y)!
view?.layer.addSublayer(line)
line.lineWidth = 8
let color = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1).cgColor
line.strokeColor = color
line.fillColor = nil
line.frame = (view?.bounds)!
path.move(to: CGPoint(x: firstPositionX!, y: firstPositionY))
}
}
override func touchesMoved(_ touches: …Run Code Online (Sandbox Code Playgroud) ios ×4
bezier ×3
iphone ×3
objective-c ×2
swift ×2
cgpoint ×1
cocoa ×1
cocoa-touch ×1
ipad ×1
swift2 ×1
swift3 ×1
uibezierpath ×1