tags:

views:

268

answers:

2

Hi all

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

A: 

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.

McWafflestix
A: 

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!");
   }
}
fatalexception