how to know the direction of rotation of UIImage in iPhone - iphone

i want to rotate the uiimage in the direction turned, i'm able to get the angle between touchesBegan and TouchesEnd points but how should i decide whether to rotate cockwise or anti-clockwise?
Plz help

Get the current orientation of the device and rotates as you wish.
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
orientation is UIDeviceOrientationLandscapeLeft and UIDeviceOrientationLandscapeRight if the device is on landscape.

Related

UIDeviceOrientation issue with iPad

I have an iPad in which I start at a landscape left orientation, however when I do:
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
it doesn't detect it as landscape left. I had to rotate it to portrait mode and then back to landscape left again, and then when I check the orientation, now it's correct. However, initially when it's launched it is not correct. Why is this? How do I resolve this?
Never use the Device Orientation if you would like to determine the Interface Orientation!
If you have a reference to the RootViewController of your main window, you could ask it for its interfaceOrientation.
If you don't, use [UIApplication sharedApplication].statusBarOrientation to determine the Interface Orientation.

iPhone - Screen Rotation?

What's the difference between UIDeviceOrientation & UIInterfaceOrientation ?
Which one should I use to detect rotation on a UIView?
UIDeviceOrientation gives you information about the physical device itself while UIInterfaceOrientation tells you about the orientation of the views it is displaying. These do not need to match; when a user uses the orientation lock or if the the device orientation is face up.
You probably want to be checking UIInterfaceOrientation and the rotation methods on UIViewController to determine when views have been or should be rotated.
UIDeviceOrientation refers to the physical orientation of the device whereas UIInterfaceOrientation refers to the orientation of the user interface.
So what you need to set is the autoResizeMask so that the view is resized correctly when its superview is resized. Set flexibleWidth and flexibleHeight for the view. Check http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIDevice_Class/Reference/UIDevice.html
Also - refer to
UIDEVICE orientation
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]

iPhone rotation on demand

Is there a way to manually check current position of device AND ask device to automatically rotate it without waiting for user to actually rotate the device?
Currently I control the rotation with several IFs in -shouldAutorotateToInterfaceOrientation but in few situations I have to stop the view from rotating and enable it again and I don't want user to rotate the device twice to have the desired orientation.
for checking Orientation
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
then based on your condition you can change device orientation as you wish..
you can use :
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
or what ever you want.
or you can go for following but this is not do
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationPortrait];

How to find out when the device is held upright horizontally and vertically using UIAccelerometer

How to find when the ipod is held straight up in the air - both horizontally and vertically.
Can any one help me ?
Thanks in advance.....
You would read the accelerometer values. A value of approx 1 on one axis, and approx 0 on all others would indicate that the devices was stationary and in a vertical (or horizontal) orientation : the 1 indicates 1 G acting through the plane of the device. Of course this would only work on Earth :-) I guess checking for 0 on all but one axis would eliminate that bug!
If I understand your question, maybe with the UIDevice orientation you can know it easily.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self selector: #selector(orientationObserver) name: UIDeviceOrientationDidChangeNotification object: nil];
On the selector take the orientation with
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
This way you avoid check the acceleration and know the orientation of the device.
UIDeviceOrientationPortrait,
UIDeviceOrientationPortraitUpsideDown,
UIDeviceOrientationLandscapeLeft,
UIDeviceOrientationLandscapeRight,
UIDeviceOrientationFaceUp,
UIDeviceOrientationFaceDown

How to control the orientation of the device in iphone / ipod?

i have to do something on rotation the device on the portrait mode but when i use the
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
//[[[UIApplication sharedApplication]keyWindow]subviews removeFromSuperview ];
// return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
return YES;
}
following code and it work fine on the simulator but when i use to install the code in the device it make the device so much sensitive that if i just a little change the position in the device it execute this code and go to the view that i m showing on the rotation of the phone
than pls anyone tell me that how can i control the sensitivity of the device i mean that i just want when user complete a 90' rotation in the position than my code should execute but it just execute if just shake the phone in the same position .
thanks for any help
Balraj verma
You probably want to buffer the orientation information; that is, only change the orientation after you have received several indications from the sensor in a row that the orientation is different from what you're currently displaying.
From my understanding of what you have written, your application is too sensitive when the device is rotated? It's difficult to understand why this is; the code you've included states that you're application is willing to accept any rotation, but you've not stated how you deal with the rotation events afterwards.
Based on the info, I can only suggest that you add a check to in your code (perhaps where the rotation event is dealt with) and obtain the orientation from the device using:
[[UIDevice currentDevice] orientation];
which will return a UIInterfaceOrientation enum stating the current orientation of the device.
UIDeviceOrientationPortrait
UIDeviceOrientationPortraitUpsideDown
UIDeviceOrientationLandscapeLeft
UIDeviceOrientationLandscapeRight
You can then use this to establish whether there's a need to change the orientation. (Note: this is iPhone OS 2.0. I believe that OS 3.0 has more including lying face up/down, etc.)
- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIDeviceOrientationLandscapeRight)
{
NSLog(#"Landscape Right!");
}
}
If you find that the orientation switches too quickly you may want to buffer the information, creating several sample points that you can compare before switching to the new orientation.