为什么我的scrollView不能以我的坐标开始?
问题描述:
我需要在我的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起始位置...
为什么?
答
您应该将viewDidLoad代码放入viewWillAppear:中,因为在viewWillAppear:之前,可能没有在viewDidLoad中设置所有内容的边界。我不明白你的最后一个问题:“如果我尝试旋转设备的scrollView开始位置...”