PDA

View Full Version : Formatting Subviews




BrooklynDon
Jan 10, 2011, 12:37 PM
First off, let me say that this is my first post on this forum. I am a newbie to iOS programming, but i'm learning.
Here is my problem: my main screen works in both landscape and portrait modes... here is the .m code:


#import "DownstateViewController.h"
#import "aboutDownstateViewController.h"
#import "AboutThisAppViewController.h"
#import "downstateServicesViewController.h"
#import "searchDownstateViewController.h"

//variables commented out to save space

aboutDownstateViewController *viewController;

//create the orientation views (Portrait and Landscape)
-(void)positionViews {
UIInterfaceOrientation destOrientation = self.interfaceOrientation; //Get the presengt orientation from the device
if (destOrientation == UIInterfaceOrientationPortrait || destOrientation == UIInterfaceOrientationPortraitUpsideDown) {
//Show Portrait Mode
downstate.frame = CGRectMake(0, 0, 321, 175);
welcomeToDownstate.frame = CGRectMake(30, 190, 261, 45);
aboutDownstate.frame = CGRectMake(20, 266, 117, 50);
downstateServices.frame = CGRectMake(20, 324, 117, 50);
searchDownstate.frame = CGRectMake(183, 266, 117, 50);
aboutThisApp.frame = CGRectMake(183, 324, 117, 50);
redAlert.frame = CGRectMake(0, 427, 320, 33);
alertMessage.frame = CGRectMake(66, 5, 196, 21);
copyright.frame = CGRectMake(26, 408, 268, 21);
} else {
//Show Landscape Mode
downstate.frame = CGRectMake(149, 0, 186, 101);
welcomeToDownstate.frame = CGRectMake(110, 102, 261, 45);
aboutDownstate.frame = CGRectMake(101, 145, 117, 50);
downstateServices.frame = CGRectMake(101, 203, 117, 50);
searchDownstate.frame = CGRectMake(264, 145, 117, 50);
aboutThisApp.frame = CGRectMake(264, 203, 117, 50);
redAlert.frame = CGRectMake(0, 267, 480, 33);
alertMessage.frame = CGRectMake(152, 5, 196, 21);
copyright.frame = CGRectMake(107, 249, 268, 21);
}
}

-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO rientation duration:(NSTimeInterval)duration {
[self positionViews];//set and animate the new position view
}

//Set up the button clicked actions
//Showing just the 4th button for clarity

-(IBAction) button4Clicked: (id) sender{
viewController = [[AboutThisAppViewController alloc] initWithNibName:@"AboutThisAppViewController"
bundle:nil];
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view
cache:YES];
[self.view addSubview:viewController.view];
[UIView commitAnimations];
}


When it goes to "About this App", I can see it well in landscape mode, but I get this in Portrait mode:
http://www.downstate.edu/bc/don/Screen shot 2011-01-05 at 10.28.26 AM.png

And this is the "About this App.m" code


#import "AboutThisAppViewController.h"

//Again, variables commented out to save space

-(IBAction) btn4Clicked:(id) sender{
[UIView beginAnimations:@"flipping view" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view.superview
cache:YES];
[self.view removeFromSuperview];
[UIView commitAnimations];
}

-(void)positionViews{
UIInterfaceOrientation destOrientation = self.interfaceOrientation;
if (destOrientation == UIInterfaceOrientationPortrait) {
header.frame = CGRectMake(0, 0, 280, 21);
} else {
header.frame = CGRectMake(100, 100, 200, 21);
}
}

-(void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceO rientation duration:(NSTimeInterval)duration{
[self positionViews];
}


I would like to show this app in both the landscape and portrait modes. What am I doing wrong in the "aboutThisApp.m" program? TIA :)