scrollview更改为更改方向

时间:2011-06-18 09:02:07

标签: iphone

我正在创建应用程序,其中我使用了scrollview和insdie scrollview我使用了imageview来显示图像。但是当我将模拟器方向更改为横向左/右时,imageview和scrollview的位置随着方向增加而向左移动同样的过程是一个阶段,滚动视图和imageview去观看。我在视图中使用了两个视图,一个用于纵向,另一个用于横向。我必须显示差异。肖像模式和landscpe模式的图像,所以任何人都可以帮助我..提前谢谢。这里有一些示例代码。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if(interfaceOrientation==UIInterfaceOrientationPortrait ||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown)
    {
        return YES;
    } else if(interfaceOrientation==UIInterfaceOrientationLandscapeLeft ||interfaceOrientation==UIInterfaceOrientationLandscapeRight)   
    {
            return YES;     
    }
    return YES;
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{
    UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

    if(orientation==UIInterfaceOrientationPortrait || orientation==UIInterfaceOrientationPortraitUpsideDown)
    {CGRect frame=CGRectMake(0,45,320,480);
        [sample_scroll_view setFrame:frame];
        sample_scroll_view.contentSize = CGSizeMake(2560,275);
        sample_scroll_view.pagingEnabled=YES;
        sample_scroll_view.autoresizingMask =
        ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
        sample_scroll_view.autoresizesSubviews = YES;
}
else if (orientation==UIInterfaceOrientationLandscapeLeft || orientation==UIInterfaceOrientationLandscapeRight)
{
CGRect frame=CGRectMake(0,45,480,275);
        [scroll_view2 setFrame:frame];
        scroll_view2.contentSize = CGSizeMake(3140,275);
        scroll_view2.maximumZoomScale = 4.0;
        scroll_view2.minimumZoomScale = 0.75;
        scroll_view2.bounces = NO;
        scroll_view2.pagingEnabled=YES;
    sample_scroll_view.autoresizingMask =
    ( UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    sample_scroll_view.autoresizesSubviews = YES;
}
}

1 个答案:

答案 0 :(得分:0)

您可以在xib文件中的View标记,自动调整模式下进行一些设置。