5

I set the content size so vertical scrolling becomes activated but I only want the user to be able to scroll north and not south. Any ideas on how I can accomplish this?

//set high greater than view
myScroll.contentSize = CGSize(width: myView.view.frame.width,height: myView.view.frame.height + 190)

I only want the ability to scroll up and disable the ability to scroll down which is the default direction of the scrollview

swiftTonio
  • 119
  • 1
  • 2
  • 6

4 Answers4

3

You can set the content offset of the scroll view to the bottom. i.e.,

myScroll.contentOffset = CGPoint(x: 0,y: 190) // Here 190 is the same value that represent the height increase done in contentSize.

Varun
  • 759
  • 6
  • 12
  • and if you want to scroll Left rather than Right (if your scrolling is only horizental) myScroll.contentOffset = CGPoint(x: yourScrollWidth,y: 0) – Letaief Achraf Nov 17 '16 at 16:21
1

Make a subclass of UIScrollView. Override layoutSubviews to make sure contentOffset.y only increases, except when it's beyond the end of the content range, so the scroll view can bounce at the bottom.

class MyScrollView: UIScrollView {
    var priorOffset = CGPoint.zero

    override func layoutSubviews() {
        var offset = contentOffset

        if offset.y < priorOffset.y {
            let yMax = contentSize.height - bounds.height
            if offset.y < yMax {
                offset.y = priorOffset.y
                contentOffset = offset
            }
        }
        priorOffset = offset

        super.layoutSubviews()
    }
}

Result:

one-way scroll view

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0
  1. select your Scrollview
  2. select identity inspector
  3. set user define attributes (see image)

    in image first 435 vertical scrolling & second 116 is horizontal scroll

Note : set your own scrolling

enter image description here

Maulik shah
  • 1,664
  • 1
  • 19
  • 45
0

You can set the direction of UIPanGestureRecognizer which is attached to your UIScrollView.

Check out some popular question which has an up-to-date answer, for example this one.

Or just go with pod 'UIPanGestureRecognizerDirection'

Community
  • 1
  • 1
iWheelBuy
  • 5,470
  • 2
  • 37
  • 71