dhr*_*hrm 28 cocoa-touch objective-c uiscrollview ios
我有一个UIScrollView
.该scrollview.contentSize
设置在所有子视图的高度UIScrollView
.当contentSize
if的高度大于高度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)
是否有一种不那么强硬的方式来做到这一点?
NJo*_*nes 74
UIScrollView
这个声音有两个属性,就像你想要的那样:
@property(nonatomic) BOOL alwaysBounceVertical; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag vertically
@property(nonatomic) BOOL alwaysBounceHorizontal; // default NO. if YES and bounces is YES, even if content is smaller than bounds, allow drag horizontally
Run Code Online (Sandbox Code Playgroud)
只需将其中一个或两个设置为,即可YES
获得反弹效果.
这也可以通过选中"水平弹跳"和/或"垂直弹跳"框在IB中设置:
迅速:
scrollView.alwaysBounceVertical = true
scrollView.alwaysBounceHorizontal = true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7615 次 |
最近记录: |