Search code examples
swiftuiscrollview

In Swift scroll view delegate is not working


import UIKit

class ViewController: UIViewController,UIScrollViewDelegate{

    @IBOutlet weak var scroll: UIScrollView!
    @IBOutlet weak var Wbs: webview!
    override func viewDidLoad() {
        super.viewDidLoad()

        scroll.backgroundColor=#colorLiteral(red: 0.4392156899, green: 0.01176470611, blue: 0.1921568662, alpha: 1)
        scroll.delegate=self
    }
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        print("as")
    }
}

I always wonder I this code is not working, I have implemented scrollViewwillBegin dragging so when I scroll I get the message I didn't get any message , So what wrong here


Solution

  • Scrollviews without sufficient content (content size equal or smaller then the scrollview) wont get that delegate called because it has no scroll.

    Make sure you have enough content and that all views you add to your scrollview have all 4 of their sides pinned, otherwise it wont work.