iPhone SDK UIScrollView 移动后没有得到触摸事件

发布于 2024-08-28 04:09:51 字数 685 浏览 6 评论 0原文

我对 UIScrollView 进行子类化,并在开始时用一些项目填充此 ShowsScrollView。填充后,我将框架和内容大小设置为此 ShowsScrollView。现在一切正常,我收到触摸事件,滚动正在工作。

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

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

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

请帮忙!

I'm subclassing UIScrollView and on the start I fill this ShowsScrollView with some items. After filling it, I setup frame and contentSize to this ShowsScrollView. Everything works fine for now, i get touches events, scrolling is working..

But after rotation to landscape, I change x and y coordinates of ShowsScrollView frame, to move it from bottom to top right corner. Then I resize it (change width and height of ShowsScrollView frame) and reorder items in this scroll. At the end I setup new contentSize.
Now i get touches event only on first 1/4 of scrollview, scrolling also work only on 1/4 of scrollview, but scroll all items in scrollview.
After all actions I write a log: NSLog(@"ViewController: setLandscape finished: size: %f, %f content: %f,%f",scrollView.frame.size.width,scrollView.frame.size.height, scrollView.contentSize.width, scrollView.contentSize.height );

Values are correct:
ViewController: setLandscape finished: size: 390.000000, 723.000000 content: 390.000000,950.000000

On rotating back to portrait, I move and resize all thing back and everything works fine..

Please help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨落□心尘 2024-09-04 04:09:52

我遇到了同样的问题,并在更改滚动视图的框架后再次设置 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)];
}

I had the same issue and managed to get it working by setting the size of self.view again AFTER changing the scrollview's frame. I don't know why this works, but it does.

// 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)];
}
不…忘初心 2024-09-04 04:09:52

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

[self.view bringSubviewToFron:scrollView];

You have to bring scrollView to front of the superView, for example:

[self.view bringSubviewToFron:scrollView];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文