iOS UIView 中的 UIScrollView
我有一个具体的问题。对于大多数人来说这可能并不重要,但我必须处理它并且我必须解决下面描述的问题。我尝试使用 Google 和 Apple SDK 文档查找有关它的一些信息,但没有成功。
我正在设计一个屏幕,其中有许多水平滚动的图像。共有三三卷相同的卷轴。每卷都有标题。我已经实现了从 UIView
派生的自定义类,并将 UIScrollView
用于滚动,将 UILabel
用于标题文本:
@interface MyView : UIView {
UIScrollView *iScrollView;
UIView *iTitleView;
}
然后我将此类的对象放在UIViewController 的视图:
@implementation MyViewController
- (void) viewDidLoad {
[super viewDidLoad];
...
iScrollViewTop = [[MyView alloc] init];
[self.view addSubview:iScrollViewTop];
...
}
@end
当我用图像填充内部滚动视图并运行我的应用程序时,它看起来不错。但有一些奇怪的行为。首先,滚动没有像我设置的那样反弹
iScrollView.bounces = NO;
,其次,当我滑动滚动时,滚动停止后,滚动条不会在一秒钟内消失。这对我来说很奇怪,因为当我通常创建一个 UIScrollView 并将其添加到 UIViewController 的视图中时,它会反弹,并且滚动条在停止时会立即消失。我尝试更改 UIScrollView
的属性,例如 orientationLockEnabled
、pagingEnabled
、canCancelContentTouches
、delaysContentTouches< /code>、
decelerationRate
等。事实上,我尝试更改 UIScrollView 的几乎所有属性,但我无法让滚动条立即消失。
如果我尝试将 UIScrollView
而不是 MyView
添加到 UIViewController.view
中,它会弹起,滚动条在停止后立即消失。另外,如果我从 UIScrollView
子类 MyView
,我也会得到正确的行为,但在这种情况下,我无法管理标题标签,因为它与其他内容一起滚动。
所以这是我的问题:
- 你知道为什么我会看到这种行为吗?
- 如何获得 UIView 封装的滚动的“通常”行为?
I have a little bit specific question. It might not matter for most people but I have had to deal with it and I had to solve the issue described below. I tried to find some information about it using Google and the Apple SDK documentation but did not succeed.
I was a designing a screen where there were many images in horizontal scrolls. There three three same scrolls. Every scroll had title. I have implemented custom class derived from UIView
and placed there UIScrollView
for scroll and UILabel
for title text:
@interface MyView : UIView {
UIScrollView *iScrollView;
UIView *iTitleView;
}
I then put objects of this class on the view of a UIViewController
:
@implementation MyViewController
- (void) viewDidLoad {
[super viewDidLoad];
...
iScrollViewTop = [[MyView alloc] init];
[self.view addSubview:iScrollViewTop];
...
}
@end
When I filled the internal scroll view with images and ran my application it looked OK. But there was some strange behavior. First, scroll did not have bounces as if I had set
iScrollView.bounces = NO;
and second, when I swiped to scroll, after the scroll stopped, the scroll bar did not disappear within one second. It was strange for me, because when I usually create a UIScrollView and add it to the UIViewController
's view it has bounces and scroll bar disappears immediately when it stops. I tried to change UIScrollView
's properties, such as directionalLockEnabled
, pagingEnabled
, canCancelContentTouches
, delaysContentTouches
, decelerationRate
and others. In fact, I have tried to change almost all properties of UIScrollView
but I could not get the scroll bars to immediately disappear.
If I try to add UIScrollView
instead MyView
to the UIViewController.view
, it bounces and scroll bar disappears immediately after it stops. Also I get correct behavior if I subclass MyView
from UIScrollView
but in this case I cannot manage the title label because it scrolls together with other content.
So here are my questions:
- Do you know why I am seeing this behavior?
- How can I get "usual" behavior for scroll encapsulated by
UIView
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
遵循此模式(westie.jpg = 360x200 的图像)
@end :
好的,下面是 hacky 代码,所以忽略我的所有其他问题,但稍后在外部视图创建中
ok, hacky code follows, so ignore all my other issues, but follow this pattern (westie.jpg = image that was 360x200)
@end
later, in your outer view creation: