重绘scrollView及其内容以横向显示

时间:2011-05-25 21:02:16

标签: objective-c uiscrollview orientation

我有一个简单的页面,顶部有一个导航栏,底部有一个标签栏,还有一个滚动视图填充了它们之间的空间。 scrollview包含一个标签和图像以及一个不可滚动的textview,它可以动态填充文本并适当调整大小。我一直试图通过使用以下方式使其在横向上工作:

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        NSLog(@"called");
        navBar.frame = CGRectMake(0, 0, 480, 32);
        sview.frame = CGRectMake(0, 32, 480, 240);
    }
    else {
        navBar.frame = CGRectMake(0, 0, 320, 44);
        sview.frame = CGRectMake(0, 44, 320, 372);

    }

}

这让我非常接近,因为导航栏和滚动视图正确调整大小并且滚动得很好,但滚动视图中的内容偏离了左侧。如何重绘内容以在scrollview中正确排列?

1 个答案:

答案 0 :(得分:1)

尼克在评论中提供了正确的答案。我只需要更改scrollview中项目的autoresizemasks。我做了:

pic.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth;

用于viewDidLoad方法中的每个项目。

相关问题