2010-04-12 71 views
1

我是UIScrollView的子類,開始時我用一些項目填充這個ShowsScrollView。填充後,我將frame和contentSize設置爲這個ShowsScrollView。一切工作正常,我現在觸摸事件,滾動正在工作..iPhone SDK UIScrollView在移動後沒有得到觸摸事件

但旋轉到風景後,我改變了X和Y座標ShowsScrollView框架,將其從右下角移到右上角。然後我調整它的大小(更改ShowsScrollView框架的寬度和高度)並重新排列此滾動條中的項目。最後,我設置了新的contentSize。 現在我只在滾動視圖的第一個1/4上觸摸事件,滾動也只在滾動視圖的1/4上工作,但滾動視圖中的所有項目。所有的動作我寫一個日誌:NSLog(@「ViewController:setLandscape finished:size:%f,%f content:%f,%f」,scrollView.frame.size.width,scrollView.frame.size.height, scrollView.contentSize.width,scrollView.contentSize.height);

值是正確的: 的ViewController:setLandscape完成:大小:390.000000,723.000000內容:390.000000,950.000000

在旋轉回縱向,我移動和調整所有的東西回來,一切工作正常..

請幫忙!

回答

0

我有同樣的問題,並設法通過設置self.view的大小後,再次改變scrollview的框架工作。我不知道這是爲什麼起作用,但確實如此。

// Set the view's frame 
if (UIDeviceOrientationIsLandscape(toOrientation)) { 
[self.view setSize:CGSizeMake(1024, 724)]; 
} else { 
[self.view setSize:CGSizeMake(768, 960)]; 
} 

// Set scrollview frame 
if (UIInterfaceOrientationIsLandscape(toOrientation)) { 
self.scrollView.frame = CGRectMake(0, 0, 100, 300); 
self.scrollView.contentSize = CGSizeMake(100, 600); 
} 
else { 
self.scrollView.frame = CGRectMake(0, 0, 300, 100); 
self.scrollView.contentSize = CGSizeMake(600, 100); 
} 

// Move your content around here 

// Set the view's frame again 
if (UIDeviceOrientationIsLandscape(toOrientation)) { 
[self.view setSize:CGSizeMake(1024, 724)]; 
} else { 
[self.view setSize:CGSizeMake(768, 960)]; 
} 
+0

嗯,你是怎麼設置自動尺寸屬性?現在我有默認的自動調整(頂部和左側),並在方法didRotateFromInterfaceOrientation我有: [self.view setSize:CGSizeMake(768,1004)]; scrollView.frame = CGRectMake(0,584,768,420); //計算並設置scrollView的內容大小 //在scrollView中移動內容 [self.view setSize:CGSizeMake(768,1004)]; 1004像素高度是因爲我有底部的tabbar,女巫有20像素高度 同樣的結果! 我也嘗試禁用自動調整和替換setSize座標爲0,0的視圖上的setSize,但是我有很大的餘量在上面.. – miham 2010-05-15 11:49:28

+1

我沒有設置自動調整,所以我猜這是任何默認值。想不到任何我設定的可能會有所作爲的東西,希望你能使它工作! – Squirtle 2010-05-17 15:36:50

0

你必須把scrollViewsuperView的前面,例如:

[self.view bringSubviewToFron:scrollView];