ios - Easy way to reset scroll view position -
this question has answer here:
i have horizontal uicollectionview, , want reset x position. tried following:
let indexpath = indexpath(row: 0, section: 1) self.collectionview.scrolltoitem(at: indexpath, at: uicollectionviewscrollposition(rawvalue: 0), animated: false) however not work, got error:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'attempt scroll invalid index path: <nsindexpath: 0x61000002d040> {length = 2, path = 1 - 0}' how scroll collection view start?
this not work if there no items
self.collectionview.scrolltoitem(at: indexpath, at: uicollectionviewscrollposition(rawvalue: 0), animated: false) use (objective c):
cgpoint topoffest = cgpointmake(0,-self.collectionview.contentinset.top); [self.collectionview setcontentoffset:topoffest animated:yes]; use (swift):
let topoffest:cgpoint = cgpoint(0,-self.collectionview.contentinset.top) collectionview?.setcontentoffset(topoffest, animated: true)
Comments
Post a Comment