2012-01-23 33 views
1

我有一個包含一堆子視圖的UIScrollView。如果視圖最初以橫向或縱向加載,則每個視圖的佈局都很好。但是,當我嘗試處理方向改變時,什麼都不會發生。UIScrollView不更新

我認爲問題在於subviews框架正在更新,但沒有重新繪製。如果設備處於縱向

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation  duration:(NSTimeInterval)duration { 
    int i = 0; 
    for(UIView *subview in [scroll subviews]) { 
     if([subview isKindOfClass:[GalleryThumbContainerView class]]) { 
      [subview setFrame:[self getFrameLandscape:i]]; 
      i++; 
     } else { 
     } 
    } 
} 

,我又把它旋轉爲橫向無子視圖新幀更新:

我用這爲我們設置的方向變化框架。

如果我將設備放在肖像中並留下視圖,那麼返回所有新幀都會更新。

這使我相信這個設置沒有被更新的問題。我曾嘗試過:

[self.view setNeedsDisplay]; 
[self.view setNeedsLayout]; 
[self.scroll setNeedsDisplay]; 
[self.scroll setNeedsLayout]; 

沒有哪個工作。

我已成功地「製造」它的工作:

  1. 拆除的滾動視圖
  2. 設置所有的子視圖的新框架
  3. 重新添加所有的子視圖回到了滾動
  4. 所有子視圖

似乎有一個更乾淨的方法來做到這一點。

我也嘗試添加一個方向更改偵聽器到我的子視圖子類(滿嘴),並存儲每個子視圖風景和肖像幀。然後由聽衆切換。這也沒有效果。

任何幫助非常感謝,並感謝您的時間。

+0

有關設置所有的意見的內容模式UIViewContentModeRedraw什麼? http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html – 2012-01-23 21:36:53

+0

您是否也調整了InterfaceOrientation上的ScrollView更改? – alex

+0

@alex是的。 – random

回答

0

爲(UIView的*在scrollView.subviews視圖)

{ 
    if ([view isKindOfClass:[UIImageView class]]) 
    { 
     [view removeFromSuperview]; 
    } 
}