2010-05-31 43 views
0

我有一個自定義視圖滾動型。現在我與旋轉有問題,認爲有旋轉後不正確的幀POS /大小。UIScrollView的自定義視圖旋轉問題

我如何可以調用CustomView旋轉後的重新定位和調整框架和內容?

- (void)setupPage 
{ 
    NSUInteger nimages = 0; 
    CGFloat cx = 0; 
    for (; ; nimages++) { 
     if (nimages == list.count) { 
      break; 
     } 

     CustomStepView *stepView = [[CustomStepView alloc] initWithFrame:CGRectZero]; 
     stepView.tag = nimages; 
     if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
     { 

      stepView.frame = CGRectMake(cx, 0.0 , 768.0f, 926.0f); 
      cx += 768.0; 
     } 
     else 
     { 
      stepView.frame = CGRectMake(cx, 0.0 , 1024.0f, 670.0f); 
      cx += 1024.0; 
     } 

     [scrollView addSubview:stepView]; 
     [stepView release]; 

    } 

    self.pageControl.numberOfPages = nimages; 

} 

回答

0

從它看起來像,你有很多子視圖(自定義視圖)在你的ScrollView。

首先,永遠不要試圖通過檢測的的UIDevice定位,所以不建議用蘋果。 對於處理您已提供的功能轉:「shouldAutorotateToInterfaceOrientation」

在此方法中,你可以簡單的運行檢測子視圖存在於您的滾動視圖內,然後循環設置每個子視圖的框架和大小。

這可能是這個樣子:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if(interfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
    for(UIView *asubview in scrollView.subviews) 
    { 
     asubview.frame = "NEW FRAME";  
    } 
    } 
    else 
    { 
     asubview.frame = "NEW FRAME"; 
    } 
} 

希望它可以幫助you..although我知道這已被要求回長:-) 乾杯

+0

你不應該改變內部框架' - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation'。你在'-will ...'或'-did ...'方法中進行了修改。 – mahboudz 2012-09-13 18:55:50