如何消除屏幕的差距?

时间:2011-11-11 12:26:58

标签: iphone

我有一个应用程序,我已经应用了更改方向的设施但是当我改变方向然后转到下一个屏幕然后在右侧显示一个间隙如果我在右侧旋转设备如图所示: enter image description here

我在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;
} 

如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

将+20添加到视图框。发生这种情况是因为它不包括状态栏空间。

答案 1 :(得分:0)

您可以根据方向使用以下属性自动调整大小控件。但要小心使用它,只需更改要自动调整大小的控件属性。

enter image description here

修改

请仔细阅读此链接iPhone SDK: Orientation (Landscape and Portrait views)我认为您不会将代码置于方向更改方法中。这个链接肯定会指导你。

使用此方法进行方向更改检测..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}