2013-10-10 48 views
1

使用Interface Builder,我創建了一個包含UIScrollView的視圖。UIScrollView的右側部分在橫向模式下不起作用

我以編程方式將按鈕添加到空的UIScrollView。

當方向改變,我用

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

來調用重置屏幕上的按鈕的方法。

之後,的UIScrollView -content得到使用setContentSize新的大小。

不管ContentSize的寬度,我只能在屏幕的第一個320像素上進行交互(滾動/或點擊按鈕) - 這是縱向模式下的屏幕寬度。

Example

當我設置contentSize寬度到2000年,我可以滾動到左邊,但只有我的第一個320像素,而不是完整的480(採用了一塊3.5英寸的iPhone)的手指。

我錯過了什麼?

回答

0

您必須重新調整滾動視圖的框架,而不僅僅是內容的大小(其實很多時候你需要調整內容大小,內容可能不會改變方向時以下改變,但只是框架)。

+0

予設定的幀中** ** willAnimateRotationToInterfaceOrientation ,但沒有結果。 –

+0

您在滾動視圖外還有其他視圖和/或手勢識別器嗎? – micantox

+0

如何轉儲!我忽略了另一個沒有調整大小的家長觀點。它現在工作:) –

0

我有一個從(UIViewController)調用的Popup(UIView)的問題。

在作爲的UIViewController隨後

func createPopup() { 
    let myPopup = MyPopup(frame: UIScreen.mainScreen().bounds) 
    self.view.addSubview(myPopup) 
} 

在彈出(UIView的)已創建彈出我需要重寫layoutSubviews如下:

override func layoutSubviews() { 
    super.layoutSubviews() 
    self.setNeedsDisplay() 

    let mainScreenBounds = UIScreen.mainScreen().bounds 

    view.frame = mainScreenBounds 
    super.frame = mainScreenBounds <-- Need to update the parent 

    ** perform additional rotation/orientation code here ** 
} 
相關問題