2012-01-31 91 views
1

当我在滚动视图中查看图像时,我改变了手机的方向,scrollview不会改变手机的方向。当方向改变时UIScrollview大小

林想知道如果有人可以向我解释如何做到这一点。

这些都是在我的界面生成器设置

enter image description here

我刚才已经做了一些研究,现在有第一选择工作,但如果我尝试另一张照片它dosnt工作..和我不能确定为什么..我的继承人代码

这是什么使这半工作

scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 


- (void)loadImage:(NSString *)myImageName 
{ 
// //Create scrollview 

    scrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]; 
    scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight); 
    scrollView.delegate = self; 

    //Create scrollviewimage 
    if ([myImageName isEqualToString:@"one"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hyundai.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 350, 550)]; 
     NSLog(@"1"); 
    } 
    if ([myImageName isEqualToString:@"two"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"keso.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 520)]; 
     NSLog(@"2"); 
    } 
    if ([myImageName isEqualToString:@"three"]) { 
     image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"conforti.png"]]; 
     containerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 600, 700)]; 
     NSLog(@"3"); 
    } 

    //Add subview 
    [containerView addSubview:image]; 
    //initViews 
// scrollView.contentSize = containerView.frame.size; 
    [scrollView addSubview:containerView]; 

    //scrolling 
    scrollView.minimumZoomScale = 1.0; 
    scrollView.maximumZoomScale = 31.0; 
    scrollView.BackgroundColor = UIColor.whiteColor; 
    [scrollView setZoomScale:scrollView.minimumZoomScale]; 

    //highrachy 
    [self.view addSubview:scrollView]; 
    scrollView = nil; 
} 

编辑:应对@D Ĵ

这是输出

2012-02-01 13:30:35.683 Diagram Test[1672:707] The view controller <UINavigationController: 0x14cdd0> returned NO from -shouldAutorotateToInterfaceOrientation: for all interface orientations. It should support at least one orientation. 
2012-02-01 13:30:44.182 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:47.097 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:47.158 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:51.509 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:51.555 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:55.473 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:55.519 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:59.293 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:30:59.352 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:02.237 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:02.281 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:03.814 Diagram Test[1672:707] height = (null)i, width = (null)i 
2012-02-01 13:31:03.858 Diagram Test[1672:707] height = (null)i, width = (null)i 
+0

将图像添加到UIScrollView的代码是什么?其他物体是否改变方向?实际上,在你发布它之后,就像你有一个UIScrollView占据整个Iphone屏幕一样,它可能是你的视图控制器。 – DJPlayer 2012-02-01 00:22:39

回答

0

这些都是正确的弹簧和支柱具有滚动视图填补取向变化的父视图。问题很可能是scrollview内容不适应。

而且看一看修改scrollview.contentSize和scrollView.contentOffest在willRotateToInterfaceOrientation:方法,如果你需要保持图像居中等

+0

我很确定内容是好的,再次检查我的问题,因为我已经用我刚刚发现的其中一张图片进行了更新。 – 2012-02-01 00:25:29

0

我有一种感觉没什么旋转..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    NSLog(@"height = %i, width = %i",scrollviewname.bounds.size.height, scrollviewname.bounds.size.width); 
    return true; 
} 

我从内存中键入该代码..所以如果有拼写错误对不起..检查这些日志,以确保uiscrollview首先旋转。

+0

我在我的问题中发布了对此的回复 – 2012-02-01 00:35:24

2

旋转scrollview将调整边界的大小,但不会调整contentSize,它不受autoresize的影响。

contentSize是滚动视图的可滚动区域,因此您需要在旋转过程中手动调整它的大小。这可能会导致其他一些调整,所以要警告旋转scrollview可能有点棘手。

例如,如果您滚动浏览图像列表,您还需要重新对齐滚动位置,并可能需要修改缩放设置以匹配新的宽度和高度。

如果您只放大单张图像,则该任务会更简单一些,因为只有缩放需要进行调整。

另一个提示:使用contentSize播放而不旋转,这样您就可以看到它是如何影响滚动和可见区域的。

+0

干杯..我发现了一些困难的方式..大时间疼痛 – 2012-02-01 00:39:09

相关问题