Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old May 20, 2008, 08:46 PM   #1
rand0m3r
macrumors regular
 
Join Date: Jun 2006
Detecting device rotation

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?
rand0m3r is offline   0 Reply With Quote
Old May 20, 2008, 09:42 PM   #2
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
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.
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old May 21, 2008, 02:39 AM   #3
rand0m3r
Thread Starter
macrumors regular
 
Join Date: Jun 2006
i've looked and it doesn't work, which is why i'm here fool.
rand0m3r is offline   0 Reply With Quote
Old May 21, 2008, 03:50 AM   #4
adrian.oconnor
macrumors 6502
 
Join Date: Jan 2008
Location: Nottingham, England
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).
adrian.oconnor is offline   0 Reply With Quote
Old May 25, 2008, 01:39 PM   #5
stadidas
macrumors regular
 
Join Date: Feb 2006
Location: Kent, United Kingdom
Quote:
Originally Posted by rand0m3r View Post
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.
stadidas is offline   0 Reply With Quote
Old Jul 4, 2008, 07:42 PM   #6
scarnie
macrumors newbie
 
Join Date: Apr 2008
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:UIDeviceOrientationDidChangeNotification object:nil];
}
Quote:
Originally Posted by adrian.oconnor View Post
Code:
   [[NSNotificationCenter defaultCenter] addObserver:self
      selector:@selector(didRotate:)
      name:@"UIDeviceOrientationDidChangeNotification" object:nil];
}
scarnie is offline   0 Reply With Quote
Old Jan 20, 2009, 01:24 AM   #7
deepak832
macrumors newbie
 
Join Date: Jun 2008
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)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)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
Attached Thumbnails
Click image for larger version

Name:	leftOrientation.png
Views:	83
Size:	48.2 KB
ID:	153799  
deepak832 is offline   0 Reply With Quote
Old Jun 15, 2009, 05:50 AM   #8
Amit Jain
macrumors member
 
Join Date: Apr 2007
Quote:
Originally Posted by deepak832 View Post
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)shouldAutorotateToInterfaceOrientationUIInterfaceOrientation)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
Amit Jain is offline   0 Reply With Quote
Old Jun 15, 2009, 08:42 AM   #9
PhoneyDeveloper
macrumors 68030
 
PhoneyDeveloper's Avatar
 
Join Date: Sep 2008
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.
PhoneyDeveloper is offline   0 Reply With Quote
Old Jun 15, 2009, 09:51 AM   #10
Amit Jain
macrumors member
 
Join Date: Apr 2007
Quote:
Originally Posted by PhoneyDeveloper View Post
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 (.
Please help
Amit Jain is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Device Tracker for iPhone & iPad ( Track and Locate your device on the Web ) haris1 iPhone and iPod touch Apps 0 Mar 1, 2014 12:15 PM
Strange problem with device rotation on iPad Duncan C iPhone/iPad Programming 3 Nov 21, 2013 07:16 PM
Device Tracker for iPhone & iPad ( Track and Locate your device on the Web ) Masood Hasny iPhone and iPod touch Apps 0 Mar 28, 2013 05:30 AM
Updated Question: Error Detecting Device (Locdown error -5) smotheredhope Jailbreaks and iOS Hacks 6 Jul 10, 2012 08:42 AM

Forum Jump

All times are GMT -5. The time now is 03:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC