我有一个UIScrollView.该scrollview.contentSize设置在所有子视图的高度UIScrollView.当contentSizeif的高度大于高度UIScrollView时,拖动视图时完全滚动.当我拖动视图时,当contentSize高度小于高度时UIScrollView没有发生任何事情.
我认为这是标准行为,因为没有什么可以滚动.但我想,UIScrollView无论如何,这有点移动.
一个可能的解决方案是确保contentSize的高度永远不会小于frame.height加上小的边距(即5px):
CGSize scrollSize = self.frame.size;
int defaultHeight = self.frame.size.height + 5;
int contentHeight = self.webView.frame.origin.y + self.webView.frame.size.height;
scrollSize.height = MAX(defaultHeight, contentHeight);
[self.scrollView setContentSize:scrollSize];
Run Code Online (Sandbox Code Playgroud)
是否有一种不那么强硬的方式来做到这一点?