简体   繁体   English

滚动视图随着更改方向而更改

[英]scrollview changes as change orientation

i'm creating app in which i used scrollview and insdie scrollview i used imageview to display images .But as i change the simulators orientation to landscape left/right the position of imageview and scrollview shifts towards left as the orientation increses while repeating same procedure a stage comes where scrollview and imageview goes off to view . 我正在创建一个应用程序,其中我使用了scrollview和insdie scrollview我使用了imageview来显示图像。但是当我将模拟器的方向更改为左/右横向时,随着方向的增加,imageview和scrollview的位置向左移动,同时重复相同的过程滚动观看和图像观看消失的阶段。 i used two views in a view one for portrait and other for landscape .i have to show diff. 我在视图中使用了两个视图,一个用于纵向视图,另一个用于横向视图。我必须显示差异。 images for portrait mode and landscpe mode so can anyone help me..thanks in advance .here is some sample code . 用于人像模式和横向模式的图像,因此任何人都可以帮助我..谢谢。这里有一些示例代码。

- (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;
}
}

您可以在xib文件的“视图”标签下的自动调整大小模式下进行一些设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM