Help iPad orientation

Discussion in 'iPhone/iPad Programming' started by Michael H, Jul 7, 2010.

  1. macrumors newbie

    Joined:
    Jan 26, 2008
    #1
    I’m sorry I posted the wrong files here are the correct ones.

    I am stuck and need HELP. I wish to use one view in portrait and a DIFFERENT view in landscape.

    “Show different views for portrait and landscape positions. Like, showing view A (in UIInterfaceOrientationPortrait and UIInterfaceOrientationPortraitUpsideDown), rotate device, then showing view B in (UIInterfaceOrientationLandscapeLeft and UIInterfaceOrientationLandscapeRight).”

    Using the view controller orientation support. I have Two issues I’m unable to resolve.
    *
    When I rotate from portrait to landscape OR landscape to portrait there is a white screen showing during animation.

    When I rotate to landscape second view appears. However, when I rotate back to portrait the second view remains and the first view doesn’t load. Second view remains and doesn't go away.
    *
    Second view files have no changes from what is given when creating them.
    *
    *
    Here is my first view files.

    iPadViewTestViewController.h


    Code:
    #import <UIKit/UIKit.h>
    
    @class LandscapeViewController;
    
    @interface iPadViewTestViewController : UIViewController {
    
    	iPadViewTestViewController *viewController;
    	
    	LandscapeViewController *landscapeViewController;
    	
    }
    
    @property (nonatomic, retain) iPadViewTestViewController *viewController;
    
    
    @property (nonatomic, retain) LandscapeViewController *landscapeViewController;
    
    @end


    iPadViewTestViewController.m


    Code:
    #import "iPadViewTestViewController.h"
    #import "LandscapeViewController.h"
    
    @implementation iPadViewTestViewController
    
    
    @synthesize viewController;
    @synthesize 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])) {
            // Custom initialization
        }
        return self;
    }
    */
    
    /*
    // Implement loadView to create a view hierarchy programmatically, without using a nib.
    - (void)loadView {
    }
    */
    
    
    /*
    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    - (void)viewDidLoad {
        [super viewDidLoad];
    }
    */
    
    
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    
    		return YES;
    
    }
    
    - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration {
    	
    		
    	
    	 if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation ==
    			 UIInterfaceOrientationPortraitUpsideDown) { 
    		self.view;
    		 
    	 } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation ==
    				UIInterfaceOrientationLandscapeRight) {
    			
    			//NSLog (@"landscape did get called"); 
    			
    			LandscapeViewController *landscape = [[LandscapeViewController alloc] initWithNibName:@"Landscape" bundle:nil];
    			[self setLandscapeViewController:landscape];
    			[landscape release];
    			
    			[viewController.view removeFromSuperview];
    			[self.view addSubview:landscapeViewController.view];
    		
    			
    			[UIView commitAnimations];
    			
    	}
    }
    
    
    
    - (void)viewDidLoad {
    	
    	[super viewDidLoad];
    }
     
    
    - (void)viewDidAppear:(BOOL)animated {
    	
    		
    	}
    
    
    - (void)didReceiveMemoryWarning {
    	// Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    	
    	// Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidUnload {
    	// Release any retained subviews of the main view.
    	// e.g. self.myOutlet = nil;
    	self.landscapeViewController = nil;
    	
    }
    
    
    - (void)dealloc {
        [super dealloc];
    }
    
    @end
     
  2. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #2
    Really need HELP! iPad orientation

    I am stuck and need HELP. I wish to use one view in portrait and a DIFFERENT view in landscape. Using the view controller orientation support. I have Two issues I’m unable to resolve.

    When I rotate from portrait to landscape OR landscape to portrait there is a white screen showing during animation.
    When I rotate to landscape second view appears. However, when I rotate back to portrait the second view remains and the first view doesn’t load. Second view remains and doesn't go away.

    Second view files have no changes from what is given when creating them.


    Here is my first view files.



    iPadViewTestViewController.m


    Code:
    #import <UIKit/UIKit.h>
     
    @class LandscapeViewController;
     
    @interface iPadViewTestViewController : UIViewController {
     
    iPadViewTestViewController *viewController;
     
    LandscapeViewController *landscapeViewController;
     
    }
     
    @property (nonatomic, retain) iPadViewTestViewController *viewController;
     
     
    @property (nonatomic, retain) LandscapeViewController *landscapeViewController;
     
    @end







    Code:
    iPadViewTestViewController.h
     
    #import "iPadViewTestAppDelegate.h"
    #import "iPadViewTestViewController.h"
     
    @implementation iPadViewTestAppDelegate
     
    @synthesize window;
    @synthesize viewController;
     
     
    #pragma mark -
    #pragma mark Application lifecycle
     
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   
       
        // Override point for customization after app launch.
        [window addSubview:viewController.view];
        [window makeKeyAndVisible];
     
    return YES;
    }
     
     
    - (void)applicationWillResignActive:(UIApplication *)application {
        /*
         Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
         Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
         */
    }
     
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        /*
         Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
         */
    }
     
    - (void)applicationWillTerminate:(UIApplication *)application {
        /*
         Called when the application is about to terminate.
         See also applicationDidEnterBackground:.
         */
    }
     
    #pragma mark -
    #pragma mark Memory management
     
    - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
        /*
         Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
         */
    }
     
    - (void)dealloc {
        [viewController release];
        [window release];
        [super dealloc];
    }
     
    @end
     
  3. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #3
    per Apple Doc's

    Per the apple documentation

    http://developer.apple.com/iphone/l...PGforiPhoneOS/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



    Code:
    #import <UIKit/UIKit.h>
    
    @class LandscapeViewController;
    
    @interface PortraitViewController : UIViewController
    {
    	BOOL isShowingLandscapeView;
    	LandscapeViewController *landscapeViewController;
    }
    
    @property (nonatomic, retain) LandscapeViewController *landscapeViewController;
    
    @end

    PortraitViewController.m

    Code:
    #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

    Code:
    #import <UIKit/UIKit.h>
    
    @interface LandscapeViewController : UIViewController
    {
    	
    }
    
    @end

    LandscapeViewController.m


    Code:
    #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
     
  4. macrumors 65816

    Joined:
    Jul 6, 2007
    #4
    Just learned about hiding the status bar yesterday.

    Add a key to your app's xxx-info.plist file. Add the "Status bar is initially hidden" key and check the checkbox.
     
  5. thread starter macrumors newbie

    Joined:
    Jan 26, 2008
    #5
    Status bar issue closed.

    Thanks PBG4 Dude the status bar advice worked. :)
     
  6. macrumors 65816

    Joined:
    Jul 6, 2007
    #6
    Yay! I'm glad it worked for you. Have you resolved your other issues?
     

Share This Page