【发布时间】:2017-01-12 07:39:26
【问题描述】:
我有一个 UIScrollView。在这个 UIScrollView 内部是一个 UIView,它包含所有其他子视图(包括一个 UIButton)。它与 UIScrollView 具有相同的边界。
我想要:
- UIScrollView 的底部不可滚动(放置 UIButton 的位置)。
- UIButton 是响应式的。
所以我将 UIScrollView 的底部设置为比 UIVIew 高一点,如下图所示:
这将使 UIButton 不响应(它在左侧布局中响应)。有什么建议吗?谢谢!
我的部分代码:
self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
[self addSubview:self.scrollView];
self.scrollContent = [[UIView alloc] initWithFrame:CGRectZero];
[self.scrollView addSubview:self.scrollContent];
self.button = [UIButton buttonWithType:UIButtonTypeCustom];
[self.scrollContent addSubview:self.button];
[self.button addTarget:self
action:@selector(buttonPressed)
forControlEvents:UIControlEventTouchUpInside];
更新:
看起来正确的做法是保持滚动视图的底部并设置它的contentSize,但是由于我使用的是autolayout,我发现contentSize的高度总是为零???
【问题讨论】:
-
好像不行。另一个问题是我最初在滚动视图之外放置了一个按钮。滚动后,按钮也没有响应...
标签: ios objective-c uiscrollview uibutton