【问题标题】:UIScrollView behaving differently in portrait mode and landscape modeUIScrollView 在纵向模式和横向模式下的行为不同
【发布时间】:2011-03-14 11:17:43
【问题描述】:

我通过 XIB 创建了一个 UIScrollVIew(name-helpView),大小为 (768,1800)。 现在我通过以下代码将其添加到另一个视图中。

-(IBAction)showHelpView:(UIButton *)sender{

if(helpViewIsShowing==NO){
    //set the content size more than the view size to make the view scroll
    helpView.contentSize = CGSizeMake(helpView.frame.size.width, 2200);

    [self.view addSubview:helpView];
    helpButton.selected=YES;
    helpView.backgroundColor=[UIColor whiteColor];
    helpView.frame=CGRectMake(0, 41, helpView.frame.size.width, helpView.frame.size.height);
    helpViewIsShowing=YES;
}
else{

    [helpView removeFromSuperview];
    helpButton.selected=NO;
    helpViewIsShowing=NO;

}

}

当我在纵向模式下运行滚动视图时,它的框架看起来很好。如果我将设备从肖像转到风景,它也可以正常工作。但是如果我在横向模式下运行代码,那么滚动视图的框架不会将自身调整为全屏大小。我还通过 XIB 提供了一个自动调整大小的蒙版。但也没有运气。 任何人都可以帮我解决这个问题....谢谢

【问题讨论】:

  • 请检查滚动视图在横向启动时的 contentSize,看看它是否是您想要的。
  • 实际上,当我处于横向模式时,我什至通过给它一个不同的框架来检查它。但即使这样似乎也不起作用。

标签: iphone ipad uiscrollview


【解决方案1】:

尝试在您的视图控制器中将此功能设置为您需要的视图大小。您可以根据需要定义高度和宽度。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Override to allow orientations other than the default portrait orientation.
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) {
        self.helpView.frame = CGRectMake(0, 0, 703,768);    

        } else {
        self.helpView.frame = CGRectMake(0, 0, 768, 1024);
        }


    return YES;
}

祝你好运

【讨论】:

  • 感谢 Kshitiz 的回复。我尝试过这种方式,但仍然无法正常工作。我发现如果我们通过代码更改 ScrollView 的大小并没有改变。在 XIB 中指定的值正在此处生成。我试图通过我的代码覆盖这些值。但它不起作用..你能告诉我一些关于这个问题的事情吗
  • @ A for Alpha:我注意到您已将帧大小设置为 768 x 1800,但 iPad 屏幕大小是 1024 x 768。您是否尝试过 ipad 分辨率,您正在 ipad rite 中运行应用程序?
  • ipad 屏幕是 768*1024,但我的视图大小几乎是 768*1500,我应该将内容大小设置为大于我的视图大小才能滚动。这就是我给出那个框架的原因。有什么问题吗??
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-17
相关资源
最近更新 更多