15 Jul 2010, 20:29
Generic-user-small

Ezequiel Hernandez (2 posts)

Per the apple documentation

http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/ViewControllerPGforiPhoneOS.pdf

Chapter 2 page 42 “Creating an Alternate Landscape Interface”

I have created two (2) View Controllers, PortraitViewController & LandscapeViewController. I am having Two (2) issues I really need help on:

When I open application up in landscape orientation, application opens showing the wrong view “PortraitViewController” and not “LandscapeViewController”.

When rotating from portrait to landscape the “LandscapeViewController” appears however, it has a blank gray status bar at top. How do I remove status bar?

PortraitViewController.h

import <UIKit/UIKit.h>

@class LandscapeViewController;

@interface PortraitViewController : UIViewController { BOOL isShowingLandscapeView; LandscapeViewController *landscapeViewController; }

@property (nonatomic, retain) LandscapeViewController *landscapeViewController;

@end

PortraitViewController.m

import “PortraitViewController.h”

#import “LandscapeViewController.h”

@implementation PortraitViewController

@synthesize landscapeViewController;

  • (void)viewDidLoad { self;

    LandscapeViewController *viewController = [[LandscapeViewController alloc] initWithNibName:@”Landscape” bundle:nil]; self.landscapeViewController = viewController; [viewController release];

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

  • (void)viewDidUnload { self.landscapeViewController = nil; }

  • (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];

    [landscapeViewController release];

    [super dealloc]; }

  • (void)orientationChanged:(NSNotification *)notification { // We must add a delay here, otherwise we’ll swap in the new view // too quickly and we’ll get an animation glitch [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0]; }

  • (void)updateLandscapeView { UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView) { [self presentModalViewController:self.landscapeViewController animated:YES]; isShowingLandscapeView = YES; } else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView || UIDeviceOrientationPortraitUpsideDown && isShowingLandscapeView) { [self dismissModalViewControllerAnimated:YES]; isShowingLandscapeView = NO; }
    }

// override to allow orientations other than the default portrait orientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); // support only portrait }

@end

LandscapeViewController.h

import <UIKit/UIKit.h>

@interface LandscapeViewController : UIViewController {

}

@end

LandscapeViewController.m

import “LandscapeViewController.h”

@implementation LandscapeViewController

// the designated initializer. Override to perform setup that is required before the view is loaded. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { self.wantsFullScreenLayout = YES; // trying to overlap the status bar.

	// when presented, we want to display using a cross dissolve
	self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}
return self; }
  • (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];

    }

  • (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated];

}

// override to allow orientations other than the default portrait orientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return UIInterfaceOrientationIsLandscape(interfaceOrientation); }

@end

  You must be logged in to comment