I want to draw an image like the following in a specific orientation.

Suppose the device lies flat on the table, the image above shows how the arrow should be drawn. The angle between the device and the table is called alpha , in which case it is zero. The arrow points directly to a predetermined location point. If you rotate the device on a table, the arrow will point in the direction of the target just like a compass.
I updated the position of the image with the following code in 2D space:
// Create the image for the compass let arrowImageView: UIImageView = UIImageView(frame: CGRectMake(100, 200, 100, 100)) arrowImageView.image = UIImage(named: "arrow.png") self.view.addSubview(arrowImageView) arrowImageView.center = self.view.center func locationManager(manager: CLLocationManager!, didUpdateHeading newHeading: CLHeading!) { var direction: Float = Float(newHeading.magneticHeading) if direction > 180 { direction = 360 - direction } else { direction = 0 - direction } // Rotate the arrow image if let arrowImageView = self.arrowImageView { UIView.animateWithDuration(3.0, animations: { () -> Void in arrowImageView.transform = CGAffineTransformMakeRotation(CGFloat(self.degreesToRadians(direction) + self.angle)) }) } let currentLocation: CLLocation = manager.location }
However, if the device rises from the table, the alpha value increases ( alpha > 0 ). The arrow image should still indicate the target location, but should be facing in perspective, taking into account the angle of the alpha. This is how it looks from the outside.

The only thing that changes in 3D space is the angle alpha . All other angles remain constant.
How to draw and rotate an arrow image in orientation (given alpha angle) in 3D space?
ios objective-c swift core-animation catransform3d
confile
source share