tags:

views:

209

answers:

2

I have this method but where should i put this method???

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver: self
  selector: @selector(receivedRotate:) name: UIDeviceOrientationDidChangeNotification
  object: nil];

// This method is called by NSNotificationCenter when the device is rotated.
-(void) receivedRotate: (NSNotification*) notification
{
    UIDeviceOrientation interfaceOrientation = [[UIDevice currentDevice] orientation];
    if(interfaceOrientation != UIDeviceOrientationUnknown)
        [self deviceInterfaceOrientationChanged:interfaceOrientation];
}
A: 

See this thread.

Zed
+1  A: 

Depends on what you are trying to do. If you merely want to change the orientation of your views to match the device, then implement willRotateToInterface and shouldAutorotateToInterfaceOrientation in your viewController. That is much simpler than anything. In shouldAutorotateToInterfaceOrientation you jus treturn a YES for every orientation that you are willing to accept. Here is what the routine looks like:

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return ((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || 
      (interfaceOrientation == UIInterfaceOrientationLandscapeRight));
}
mahboudz