为什么我的scrollView不以我的坐标开始?

问题描述

| 我需要在我的iPad App中放置一个scrollView(内部带有文本滚动)。 我使用以下代码
- (void)showRootPopoverButtonItem:(UIBarButtonItem*)barButtonItem 
{
    movie_scroll.frame = CGRectMake(50,430,700,600);
    movie_scroll.directionalLockEnabled = YES;
    movie_detail.frame = CGRectMake(0,600,400);

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

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

    NSLog(@\"You are in landscape from invalidateRootPopoverButtonItem\"); 
}
- (void)viewDidLoad
//change position for scrollView
if (UIDeviceOrientationIsLandscape(self.interfaceOrientation))
{
    movie_scroll.frame = CGRectMake(50,300);

    NSLog(@\"You are in  landscape from viewDidLoad\");   
}
else 
{
    movie_scroll.frame = CGRectMake(50,400);

    NSLog(@\"You are in portrait da viewDidLoad\");   
}
好吧,当我第一次以纵向运行该应用程序时,我的位置没有scrollView。如果我尝试旋转设备,则scrollView的起始位置... 为什么?     

解决方法

您可能应该将viewDidLoad代码放入viewWillAppear:中,因为可能未在viewWidAppear:之前在viewDidLoad中设置所有内容的界限。我不明白您的最后一个问题:\“如果我尝试旋转设备,则scrollView的起始位置... \”