0

I have an application in which I have apply facility to change orientation of view but when I change the orientation then go to next screen then there show a gap on right side if I rotate device in right side as show in image: enter image description here

I use this code in viewcontroller.m:

-(void) viewWillAppear:(BOOL)animated{
    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    [self willAnimateRotationToInterfaceOrientation:orientation duration:0];


}

-(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown )
    {

        lgo_imag.frame=CGRectMake(0, 0, 320, 44);
        btn_settings.frame=CGRectMake(238, 3, 72, 37);
        btn_alarm_activity.frame=CGRectMake(125, 10, 70, 85);
        btn_alarm_screen.frame=CGRectMake(48, 210, 225, 55);
        btn_routine_screen.frame=CGRectMake(48, 275, 225, 55);
        btn_view_info.frame=CGRectMake(48, 340, 225, 55);
        lable_alarm_value.frame=CGRectMake(25, 100, 270, 81);
        scroll_view.frame=CGRectMake(0, 44, 320, 416);
        scroll_view.contentSize=CGSizeMake(320  ,416);

    }
    else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
    {


        lgo_imag.frame=CGRectMake(0, 0, 480, 44);
        btn_settings.frame=CGRectMake(398, 3, 72, 37);
        btn_alarm_activity.frame=CGRectMake(205, 10, 70, 85);
        btn_alarm_screen.frame=CGRectMake(128, 210, 225, 55);
        btn_routine_screen.frame=CGRectMake(128, 275, 225, 55);
        btn_view_info.frame=CGRectMake(128, 340, 225, 55);
        lable_alarm_value.frame=CGRectMake(125, 100, 270, 81);
        scroll_view.frame=CGRectMake(0, 44, 480, 320);
        scroll_view.contentSize=CGSizeMake(480  ,470);
    }


}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
    return YES;
} 

How fix that problem?

ios
  • 552
  • 5
  • 22
  • 1
    Looks to me like you need to recalculate your sizes. The landscape view certainly isn't 480 x 470. – Hot Licks Nov 11 '11 at 12:33
  • The purple is presumably the background colour of the controller's view? What autoresizing flags do you have set? You also shouldn't need to call willAnimate... explicitly under any circumstances. – Tommy Nov 11 '11 at 12:35

2 Answers2

0

Add +20 to the view frame. This happens because its not including status bar space.

DivineDesert
  • 6,924
  • 1
  • 29
  • 61
0

You can use the below property for AutoSizing the controls based on orientation. But be careful in using it, only change those controls property which you want to autosize.

enter image description here

EDIT

Please go through this link iPhone SDK: Orientation (Landscape and Portrait views) I think you are not putting your code in orientation changing method. This link will definitely guide you.

Use this method for orientation change detection..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}
Community
  • 1
  • 1
DShah
  • 9,768
  • 11
  • 71
  • 127
  • i do that but not effected my appkliation – ios Nov 12 '11 at 07:13
  • In above code set your main frame i.e your view at y=20 axis and x=480 Because your default view size is always 460 which is 20 less for Status Bar. SO you need to set your frame of View and not of that controls (for landscape mode only). – DShah Nov 12 '11 at 08:19