I am developing an app that moves a ball along a bezier curve and it works as expected on an iphone 8 plus but when I test on an ipad the animation does not move on the same path as on the iphone. How can I get these to move along the same path for each device. I realize that the xy co-ordinates are different for each device
Replies
There different coordinate systems :
- UIKit : y axis downward
- Core Graphics : y axis upward
I don't think there is a difference between iOS and iPadOS.
-
I did review the information and it did not specifically answer my question. Anyone else have any thoughts?
-
—
Claude31
-
—
dino62454
-
—
dino62454
Add a CommentCould you show the code where you define Bezier Path ?
here is a sample of the curve code. I am currently using x,y co-ordinates from input. My question is: if I run this on an iphone 8 plus it looks ok but if I run on an ipad the curve is not the same. I assume it is due to the size difference. How do I set the co-ordinates correctly for any device?
path = UIBezierPath() //new code 2-9-22 //addAnimation let moveAlongPath = CAKeyframeAnimation(keyPath: "position")
// newSTx, newSTy path.move(to: CGPoint(x: 92, y: 650)) // HPx HPy arx - 12 iny rfx rfy path.addCurve(to: CGPoint(x: 80, y: 100), controlPoint1: CGPoint(x: (newAx - 12), y: 525), controlPoint2: CGPoint(x: newRFx, y: newRFy)) let shapeLayer = CAShapeLayer() shapeLayer.path = path.cgPath shapeLayer.strokeColor = UIColor.clear.cgColor shapeLayer.fillColor = UIColor.clear.cgColor shapeLayer.lineWidth = 3.0 self.view.layer.addSublayer(shapeLayer) moveAlongPath.path = path.cgPath moveAlongPath.duration = 5 moveAlongPath.repeatCount = 0 moveAlongPath.calculationMode = CAAnimationCalculationMode.paced moveAlongPath.timingFunctions = [CAMediaTimingFunction(name: CAMediaTimingFunctionName.easeInEaseOut)] self.moveAlongPath = moveAlongPath let layer = createLayer() layer.add(moveAlongPath, forKey: "animate along Path")Adding to my question. is there a calculation for xy co-ordinates along a bezier curve or a line drawn from one point to another depending on which device you use? EX: on an iphone 8 plus I start a line on x:92, y:650. In order to position to the same spot on the view for an ipad, how is this calculated? Or does this need to be done manually for each device?