2011-03-14 114 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

相關問題