0

I'm working on a project in which when the user press a button a video will be played, I have to program this app for all orientations. I have added images as background for buttons given those buttons position based on the size of the superview like this:

button1.frame = CGRectMake(0.15 * (self.view.frame.size.width),0.15 * (self.view.frame.size.height), 0.2 * (self.view.frame.size.width), 0.2 * (self.view.frame.size.height)); 

When I start the app in portrait it's view is fine and also when I rotate it works fine :

screenshot portrait

But if I start my app in landscape it shows a view like this:

screenshot landscape

I'v used a lot of code to resize views and subviews:

-(void) viewDidLoad { ... self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self.view setAutoresizesSubviews:YES]; button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; ... } 

and in didRotateFromInterfaceOrientation() and willRotateToInterfaceOrientation():

... self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; [self.view setAutoresizesSubviews:YES]; button1.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin; ... 

I'v also specified YES for return in shouldAutoRotate(). What am I lacking here? Any help will be appreciated.

2
  • Get rid of this older approach and take the advantage of Autolayout. Things will be easier for you. Commented Nov 15, 2013 at 12:07
  • Ya thank you, but I'm programming for IOS 5.0 and also I can't disobey my orders, not to use .xib files or storyboard. Commented Nov 15, 2013 at 12:18

1 Answer 1

1
 you have to declaration below and all give them in viewDidLoad but frame give in this code -(void)viewWillAppear:(BOOL)animated { [self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:1.0]; UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation == UIInterfaceOrientationLandscapeRight || orientation == UIInterfaceOrientationLandscapeLeft) { [self setFrameForLeftAndRightOrientation]; } else if(orientation == UIInterfaceOrientationPortrait ) { [self setFrameForPortraitAndUpsideDownOrientation]; } } - (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { [self setFrameForLeftAndRightOrientation]; } else if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { [self setFrameForPortraitAndUpsideDownOrientation]; } } -(void)setFrameForLeftAndRightOrientation { if(IS_IPAD) { } else if(IS_IPHONE) { if ([[UIScreen mainScreen] bounds].size.height == 568) { } else { } } } -(void)setFrameForPortraitAndUpsideDownOrientation { if(IS_IPAD) { } else if(IS_IPHONE) { if ([[UIScreen mainScreen] bounds].size.height == 568) { } else { } } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.