Reputation: 341
I need present UICollectionView, with a different element (not only first) without animation.
my code:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
DispatchQueue.main.async {
var newPoint = self.productCollectionView.contentOffset
newPoint.x = (UIScreen.main.bounds.width * CGFloat(self.currentPage)) + 1
self.productCollectionView.contentOffset = newPoint
}
}
Upvotes: 0
Views: 60
Reputation: 535801
Instead of setting contentOffset
, call the setContentOffset(_:, animated:)
method with an animated:
value of false
.
Also I would suggest removing the async
and moving your code to viewDidLayoutSubviews
. That way, your code will run before the user sees anything, but after the initial layout of the view has been achieved. This method can be called many times, so you will have to use a Bool instance property to make sure it only runs once.
Upvotes: 1