1

我正在继承 UIScrollView 并在开始时用一些项目填充这个 ShowsScrollView。填充后,我将 frame 和 contentSize 设置为此 ShowsScrollView。现在一切正常,我得到了触摸事件,滚动正在工作..

但是在旋转到横向后,我更改了 ShowsScrollView 框架的 x 和 y 坐标,将其从底部移动到右上角。然后我调整它的大小(更改 ShowsScrollView 框架的宽度和高度)并重新排序此滚动中的项目。最后我设置了新的 contentSize。现在我只在滚动视图的前 1/4 上获得触摸事件,滚动也只在滚动视图的 1/4 上起作用,但滚动滚动视图中的所有项目。在所有操作之后我写了一个日志: NSLog(@"ViewController: setLandscape finished: size: %f, %f content: %f,%f",scrollView.frame.size.width,scrollView.frame.size.height, scrollView .contentSize.width,scrollView.contentSize.height);

值是正确的: ViewController: setLandscape finished: size: 390.000000, 723.000000 content: 390.000000,950.000000

在旋转回纵向时,我将所有东西移动并调整大小,一切正常..

请帮忙!

4

2 回答 2

0

我遇到了同样的问题,并设法通过在更改滚动视图的框架后再次设置 self.view 的大小来使其正常工作。我不知道为什么会这样,但确实如此。

// Set the view's frame
if (UIDeviceOrientationIsLandscape(toOrientation)) {
 [self.view setSize:CGSizeMake(1024, 724)];
} else {
 [self.view setSize:CGSizeMake(768, 960)];
}

// Set scrollview frame
if (UIInterfaceOrientationIsLandscape(toOrientation)) {
 self.scrollView.frame = CGRectMake(0, 0, 100, 300);
 self.scrollView.contentSize = CGSizeMake(100, 600);
}
else {
 self.scrollView.frame = CGRectMake(0, 0, 300, 100);
 self.scrollView.contentSize = CGSizeMake(600, 100);
}

// Move your content around here

// Set the view's frame again
if (UIDeviceOrientationIsLandscape(toOrientation)) {
 [self.view setSize:CGSizeMake(1024, 724)];
} else {
 [self.view setSize:CGSizeMake(768, 960)];
}
于 2010-05-14T10:02:22.180 回答
0

你必须带到scrollView前面superView,例如:

[self.view bringSubviewToFron:scrollView];
于 2012-08-07T09:53:24.257 回答