How can I make a UIScrollView
scroll to the bottom within my code? Or in a more generic way, to any point of a subview?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How can I add media attachments to my push notific
Using UIScrollView's
setContentOffset:animated:
function to scroll to the bottom in Swift.A good way to ensure the bottom of your content is visible is to use the formula:
This ensures the bottom edge of your content is always at or above the bottom edge of the view. The
MIN(0, ...)
is required becauseUITableView
(and probablyUIScrollView
) ensurescontentOffsetY >= 0
when the user tries to scroll by visibly snappingcontentOffsetY = 0
. This looks pretty weird to the user.The code to implement this is:
Didn't work for me, when I tried to use it in
UITableViewController
onself.tableView
(iOS 4.1)
, after addingfooterView
. It scrolls out of the borders, showing black screen.Alternative solution:
A swifty implementation:
You call the extension like this :
A Swift 2.2 solution, taking
contentInset
into accountThis should be in an extension
Note that you may want to check if
bottomOffset.y > 0
before scrollWith an (optional) footerView and contentInset, the solution is: