PDA

View Full Version : Detecting device rotation




rand0m3r
May 20, 2008, 08:46 PM
right now i'm doing this:

UIDevice myDevice = [UIDevice currentDevice];
[myDevice beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation currentOrientation = [myDevice orientation];

but it doesn't detect an iphone that is rotated (in the simulator)? how do i actually pick up the notifcations?



Sayer
May 20, 2008, 09:42 PM
There is a ton of sample code for iPhone that covers all of this fundamental stuff.

Try looking in the iPhone dev site. The sample code are complete working solutions covering various topics so you don't have to ask a forum on a Mac rumors web site.

rand0m3r
May 21, 2008, 02:39 AM
i've looked and it doesn't work, which is why i'm here fool.

adrian.oconnor
May 21, 2008, 03:50 AM
I've just tested on beta 5 and the notification definitely is generated in the simulator.

Here's my code. Out of interested, I added this to the WhichWayUp sample so I could see the crate turning (which will help you test it on real hardware).


- (void) didRotate:(NSNotification *)notification
{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

if (orientation == UIDeviceOrientationLandscapeLeft)
{
NSLog(@"Landscape Left!");
}
}

- (void)applicationDidFinishLaunching:(UIApplication *)application {

[window addSubview:crateViewController.view];

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}


That is in the AppDelegate class. Let us know how you get on!

P.S. I don't think the samples cover using the notification (WhichWayUp seems to use some built-in UIView magic - the rotation appears to happen automatically in the View).

stadidas
May 25, 2008, 01:39 PM
i've looked and it doesn't work, which is why i'm here fool.

When you come to a forum to ask for help, you might want to think about being polite to people who are trying to help you and not be such a cock.

scarnie
Jul 4, 2008, 07:42 PM
There is already a predefined constant for the device orientation notification, which you should use in place of the literal string in case Apple decides to change it in the future.


[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}




[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didRotate:)
name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}

deepak832
Jan 20, 2009, 01:24 AM
Hi all,

I am implementing orientation in my application view. But when my device rotate to left or right with that my image is also rotates but that time a blank black view is display in 1/4 part of the screen, i don't know why.
I am just doing
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}


I am attaching the screen which i am getting after rotation, in that the left corner black frame is displaying after rotation.


Please help me how can i solve this problem.


Thanks in Advance,
Deepak
www.umundo.com

Amit Jain
Jun 15, 2009, 05:50 AM
Hi all,

I am implementing orientation in my application view. But when my device rotate to left or right with that my image is also rotates but that time a blank black view is display in 1/4 part of the screen, i don't know why.
I am just doing
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}


I am attaching the screen which i am getting after rotation, in that the left corner black frame is displaying after rotation.


Please help me how can i solve this problem.


Thanks in Advance,
Deepak
www.umundo.com

Have you/anyone got the answer for the same problem.
Please let me know.
Thanks

PhoneyDeveloper
Jun 15, 2009, 08:42 AM
You need to set the autoResizeMask so that the view is resized correctly when its superview is resized. Set flexibleWidth and flexibleHeight for the view.

Amit Jain
Jun 15, 2009, 09:51 AM
You need to set the autoResizeMask so that the view is resized correctly when its superview is resized. Set flexibleWidth and flexibleHeight for the view.

As the shouldrotate.. method is not called so we have written in loadview method but no effect :o(.
Please help