iPhone SDK UIScrollView移动后无法获得触摸事件

时间:2010-04-12 10:14:44

标签: iphone-sdk-3.0 uiscrollview ipad uiscrollviewdelegate

我是UIScrollView的子类,在开始时我用一些项填充这个ShowsScrollView。填充后,我将frame和contentSize设置为此ShowsScrollView。一切都运行正常,我接触事件,滚动工作..

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

值正确: ViewController:setLandscape完成:大小:390.000000,723.000000内容:390.000000,950.000000

在旋转回肖像时,我移动并调整所有东西的大小,一切正常......

请帮忙!

2 个答案:

答案 0 :(得分:0)

我有同样的问题,并设法通过在更改scrollview的框架后再次设置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)];
}

答案 1 :(得分:0)

您必须将scrollView带到superView的前面,例如:

[self.view bringSubviewToFron:scrollView];