This should be a VERY easy problem but I'm having trouble getting the desired result. I have horizontally scrolling UIScrollView with a width of 320. The width of its content is 5000. I'm trying to center the content with:
// 'self' is the UIScrollView
CGFloat newContentOffsetX = (self.width/2) + (self.contentSize.width/2);
self.contentOffset = CGPointMake(newContentOffsetX, 0);
I don't understand why this is not centering the content. Can you see something wrong with the calculations?
I think you want:
diagram:
Use below code:
Swift 4
Scroll to center of content of
ScrollView
Not the best solution but might work for you