简体   繁体   中英

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 . 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文件的“视图”标签下的自动调整大小模式下进行一些设置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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