2010-06-14 24 views
2

我做了一個UIViewController,它以編程方式生成一個UIScrollView。一切都很好,但是當我旋轉設備,UIScollView應該調整大小,因此它需要我的視圖的完整寬度。Autoresize UIScrollView

有沒有辦法做到這一點,而不重建完整的UIScrollView?

Thx很多! 塞巴斯蒂安

這就是所謂的在我viewDidLoad中:

-(void)buildmyScroller { 
    myScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 800, 768, 100)]; 


    //...adding some subviews to myScroller 


    thumbScroller.contentSize = CGSizeMake(3000, 100); 
    [[self view] addSubview:myScroller]; 
} 

然後我試圖調整myScroller這一點,當我用SETFRAME,我說myScroller不會對此作出迴應...:

-(void)changemyScroller { 
     UIInterfaceOrientation interfaceOrientation = self.interfaceOrientation; 
    if (interfaceOrientation == UIInterfaceOrientationPortrait) { 
     [thumbScroller setFrame:CGRectMake(0, 805, 768, 150)]; 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){ 
     thumbScroller.frame = CGRectMake(0, 805, 768, 150); 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft){ 
     thumbScroller.frame = CGRectMake(0, 549, 1024, 150); 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
     thumbScroller.frame = CGRectMake(0, 549, 1024, 150); 
    } 
} 

並在didAnimateFirstHalf中調用該方法...因爲我不確定要在哪裏調用它。

Thx很多!

回答

2

[scrollView setFrame:CGRectmake(x,y,width,height)]; //也許你需要爲scrollView的內容做同樣的事情,以使它適合你的佈局

應該這樣做。如果需要進行轉換,可以將其包裝在UIAnimation塊中。

+0

非常感謝!解決方案可以很容易:) – wolfrevo 2010-06-14 22:04:59

+0

還有一個問題,我的滾動現在適合我的佈局和內容也有正確的大小,但是當我開始在橫向(scrollwidth 1024px)和旋轉zu肖像(scrollwidth 768px)我不能使用滾輪。當我開始縱向並旋轉到橫向時,我只能在第一個768像素進行交互,所以在右側我無法與滾動器交互。當我轉到另一個視圖時,回到包含scrollview的視圖,我可以使用它。所以在顯示時不能更改scrollView?或者我應該在哪裏改變它?謝謝。 – wolfrevo 2010-06-15 08:52:41

+0

嗨我猜你在loadView或viewDidLoad中設置了你的UIScrollView?也許甚至init? (這意味着只有在調用這些函數時纔會更新它)。嘗試在viewDidLoad中放置UIScrollView的實例,但是在單獨的函數中設置,更改內容和方向。現在,您可以從viewWillAppear和ShouldAutoRotate中調用此函數...因此,您在第一次加載時,旋轉時以及轉到另一個視圖時都會發生此設置。 – RickiG 2010-06-15 12:15:24

0

試試這個:

if(self.rowNumber == 0){ 
    /******************* Scroller Setup *****************/ 
    // how many pages 
    int pageCount = 5; 
    //set up the scrollView 
    UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 960)]; 
    // support for Landscape Orienation 
    if(UIInterfaceOrientationLandscapeLeft){ 
     [scroller setFrame:CGRectMake(0,0,1024, 704)]; 
    } 
    if(UIInterfaceOrientationLandscapeRight){ 
     [scroller setFrame:CGRectMake(0,0,1024, 704)]; 
    }