我需要将一个scrollView(里面有一个文本滚动)放到我的iPad App中。
我使用此代码:
- (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 :(得分:0)
你应该把viewDidLoad代码放到viewWillAppear:中,因为在viewWillAppear:之前,viewDidLoad中可能没有设置所有内容的边界。我不明白你的上一个问题:“如果我尝试旋转设备,则滚动视图的起始位置......”