Balraj
Balraj

Reputation:

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

Upvotes: 1

Views: 588

Answers (2)

Paul McCabe
Paul McCabe

Reputation: 1554

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.

Upvotes: 0

Paul Sonier
Paul Sonier

Reputation: 39480

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.

Upvotes: 1

Related Questions