Hello, I puzzle over the following: I need to have a horizon level on the phone so that it is displayed as a line or accurate, but when the phone is rotated (in any plane), this line goes either up or down. (We hold the phone in our hands, either portrait or landscape orientation)
To understand: Take a pencil horizontally at eye level and rotate your head in any direction, the line of the pencil (it’s the horizon) will either move up (if your head is downward), etc. Here you need something the same to do on the iPhone. A vivid example of this is the spirit level application in the standard set of iPhone (open the compass and swipe to the left do)
I know how to transform the line for example to be always horizontal, regardless of the rotation of the phone:
CMDeviceMotion *data; double rotation = atan2(data.gravity.x, data.gravity.y) + M_PI; self.myLineHoriz.transform = CGAffineTransformMakeRotation(rotation); But how to make the line tilt up or down from the tilt of the phone ??
It is necessary to calculate the center of coordinates of this line and change it depending on the slope. I've been puzzling for several days now, but there are no positive thoughts.