Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

rand0m3r

macrumors regular
Original poster
Jun 30, 2006
115
1
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?
 
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.
 
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).

Code:
- (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).
 
Minor change

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.

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

Code:
   [[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(didRotate:)
      name:[B][COLOR="Red"]@"UIDeviceOrientationDidChangeNotification"[/COLOR][/B] object:nil];
}
 
Problem when Rotating

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
 

Attachments

  • leftOrientation.png
    leftOrientation.png
    48.2 KB · Views: 253
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
 
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.
 
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 :eek:(.
Please help
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.