2011-03-14 100 views
0

我通过XIB创建了一个UIScrollVIew(name-helpView),大小为(768,1800)。 现在我通过下面的代码将其添加到另一个视图。UIScrollView在纵向模式和横向模式下的行为不同

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

} 

}

当我在纵向模式运行它滚动视图的帧出现细。 Itz也工作得很好,如果我把设备从肖像转到景观。但是,如果我在横向模式下运行代码,那么scrollview的框架不会将其自身调整为全屏大小。我还通过XIB提供了一个自动调整大小的遮罩。但是也没有运气。 任何人都可以帮助我这个请... .... Thanku

+0

请检查连接contentSize滚动视图,当它在景观开始​​,看看你是否需要它的人。 – visakh7 2011-03-14 11:23:12

+0

实际上,当我处于横向模式时,我通过给它一个不同的框架来检查它。但即使这似乎没有工作。 – 2011-03-14 11:27:45

回答

2

尝试设置在您的视图控制器此功能视图框架视图大小您required.you可以根据您的要求定义高度和宽度。

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

好运

+0

感谢答复Kshitiz。我试过这种方式,但它仍然没有工作。我发现如果我们通过代码改变它,ScrollView的大小不会改变。在这里生成XIB中指定的值。我试图通过我的代码覆盖这些值。但它力气工作..你能告诉我一些事情在这个问题上,请 – 2011-03-14 11:53:53

+0

@ A阿尔法:我已经注意到你已经设置帧大小为768 1800年,但iPad的屏幕尺寸是1024 768.did你尝试的iPad的决议,你正在iPad应用程序中运行吗? – 2011-03-14 11:59:38

+0

iPad的屏幕是768 * 1024,但我的视图大小几乎是768 * 1500,我应该设置的内容大小超过我的视图大小滚动。这就是我给出这个框架的原因。有没有问题呢? – 2011-03-15 11:42:29

相关问题