I have an image that describes a head of a monkey. I want that the head of the monkey always face up. When you turn the device the head of the monkey turns too, but I want that in spite o开发者_运维技巧f the rotation of the iphone the monkey head dooesn't turn (like a compass).
How can I do this?
If you want to follow the device as it turns you'll have to track with the CLLocationManager.
But if you just want the monkey to be upright as the user transistions from portrait to landscape (and their opposites) then maybe the UIInterfaceOrientation will do the trick:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- to do rotations, with animations, this link might help.
- to follow orientation of device it is another story...
probably involving compass using CLLocationManager :) :
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
or better, using gyroscope
Make sure to look at Apple documentation, there and there Also give a look at Apple sample codes :
精彩评论