2011-04-14 74 views
0

我需要在我的iPad應用程序中放置一個scrollView(帶有文本滾動內部)。爲什麼我的scrollView不能以我的座標開始?

我已經使用此代碼:

- (void)showRootPopoverButtonItem:(UIBarButtonItem*)barButtonItem 
{ 
    movie_scroll.frame = CGRectMake(50, 430, 700, 600); 
    movie_scroll.directionalLockEnabled = YES; 
    movie_detail.frame = CGRectMake(0, 0, 600, 400); 

    NSLog(@"You are in portrait from showRootPopoverButtonItem"); 
} 

- (void)invalidateRootPopoverButtonItem:(UIBarButtonItem*)barButtonItem 
{ 
    movie_scroll.frame = CGRectMake(50, 540, 700, 400); 
    movie_scroll.directionalLockEnabled = YES; 
    movie_detail.frame = CGRectMake(0, 0, 600, 300); 

    NSLog(@"You are in landscape from invalidateRootPopoverButtonItem"); 
} 

這太- (void)viewDidLoad

//change position for scrollView 
if (UIDeviceOrientationIsLandscape(self.interfaceOrientation)) 
{ 
    movie_scroll.frame = CGRectMake(50, 540, 700, 400); 
    movie_scroll.directionalLockEnabled = YES; 
    movie_detail.frame = CGRectMake(0, 0, 600, 300); 

    NSLog(@"You are in landscape from viewDidLoad"); 
} 
else 
{ 
    movie_scroll.frame = CGRectMake(50, 430, 700, 600); 
    movie_scroll.directionalLockEnabled = YES; 
    movie_detail.frame = CGRectMake(0, 0, 600, 400); 

    NSLog(@"You are in portrait da viewDidLoad"); 
} 

好吧,當我在肖像首次運行該應用程序時我沒有在滾動視圖的位置。如果我嘗試旋轉設備的scrollView起始位置...

爲什麼?

回答

0

您應該將viewDidLoad代碼放入viewWillAppear:中,因爲在viewWillAppear:之前,可能沒有在viewDidLoad中設置所有內容的邊界。我不明白你的最後一個問題:「如果我嘗試旋轉設備的scrollView開始位置...」

相關問題