Detecting rotation to landscape manually

I am working on an iPhone application based on UITabBarController and UIViewControllers for each page. The app needs to run in portrait mode only, so every view controller + app delegate goes with this line of code:

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
 return (interfaceOrientation == UIInterfaceOrientationPortrait);

There is one view controller where I would like to pop up a UIImageView when the iPhone is rotaed to landscapeleft. The design of the image looks landscape, although the width and height are 320x460 ( so its portrait ).

How can/should I detect this type of rotation manually, just in this specific view controller, withouth having an auto rotation on the entire view?




I added this listener in the viewDidLoad:

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

the didRotate looks like this:

- (void) didRotate:(NSNotification *)notification

        UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

        if (orientation == UIDeviceOrientationLandscapeLeft)
            //your code here



I needed that in an old project - hope it still works...

1) Register a notification:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self

2) Then you can test against the rotation on change:

-(void) detectOrientation {
    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || 
        ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
        [self doLandscapeThings];
    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {
        [self doPortraitThings];

Hope that helps!

better code to Comic Sans answer would be below.. His code will not always fire correctly ( only 80% of the time in my testing)

-(void) detectOrientation {
    if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
        [self setupForLandscape];
    } else if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) {
        [self setupForPortrait];

Need Your Help

How does Node.js perform compared to Apache?

performance apache node.js scalability

Is Node.js quicker and more scalable than Apache? Are there any performance figures to back up Node.js's performance for a web application over Apache?

Tomcat manager/html is not available?

tomcat manager-app

Hi I just installed Tomcat and and am trying to get it up and running however whenever I try to navigate to manager/html it gives me this error "The requested resource (/manager/html) is not availa...