johnvuko / JT3DScrollView

ScrollView with custom effects during the scroll for iOS
MIT License
491 stars 72 forks source link

Paging #6

Open AndrewVinod opened 8 years ago

AndrewVinod commented 8 years ago

I added this as a horizontal scroll view to an app that only uses landscape orientation. I can't stop it from allowing vertical scrolling. It also does not page the the correct x coordinate. Only the first subview is in the correct position. I'm developing on iOS 9.3. Any help would be appreciated.

johnvuko commented 8 years ago

You must have a problem either with the constraints of the scrollview or with the contentSize property. When I created this lib, I didn't use Autolayout, so you have to set the contentSize manually and position the elements inside manually also. Something like:

var x : CGFloat = 0.0

pageControl.currentPage = 0
pageControl.numberOfPages = scrollView.subviews.count

for view in scrollView.subviews {    
    view.frame = CGRect(x: x, y: 0, width: CGRectGetWidth(scrollView.frame), height: CGRectGetHeight(scrollView.frame))
    x = CGRectGetMaxX(placeView.frame)
}

scrollView.contentSize = CGSize(width: x, height: CGRectGetHeight(scrollView.frame))
scrollView.setContentOffset(CGPoint(), animated: false)
AndrewVinod commented 8 years ago

Setting this in viewDidLayoutSubviews works. Thanks.