Bhawna Shah
Bhawna Shah

Reputation: 13

UIScrollView not working in swift 3

I have made a baseViewController which is derived from UIViewController, SlideMenuDelegate and UIWebViewDelegate Then I have created subclass which are derived from baseviewcontroller

  1. LoginVC - displays login screen
  2. PlayVC - shows a webview if login is successful.

Everything is fine except that webview is not scrolling at all.

I have tried everything suggested in all posts so far regarding scrolling Below is my code written in PlayVC.swift

@IBOutlet weak var web1: UIWebView!

override func viewDidLoad() {
    super.viewDidLoad()
    addSlideMenuButton()


    let webUrl : URL = URL(string: "http://brainyknights.com")!
    let webRequest : URLRequest = URLRequest(url: webUrl)

    web1.scalesPageToFit = true
    web1.isUserInteractionEnabled = true
    web1.scrollView.isScrollEnabled = true
    web1.loadRequest(webRequest)

    // Do any additional setup after loading the view.
}

Upvotes: 0

Views: 532

Answers (2)

Reinier Melian
Reinier Melian

Reputation: 20804

According Apple Documentation

scales​Page​To​Fit

A Boolean value determining whether the webpage scales to fit the view and the user can change the scale.

if web1.scalesPageToFit is true then the web content will fit in your UIWebView frame and the contentSize will have the same height and width as your UIWebViewframe making imposible to be scrollable

so remove this line and must work

web1.scalesPageToFit = true 

I hope this helps you

Upvotes: 1

tabassum
tabassum

Reputation: 1110

remove this line web1.scalesPageToFit = true

@IBOutlet weak var web1: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        addSlideMenuButton()


        let webUrl : URL = URL(string: "http://brainyknights.com")!
        let webRequest : URLRequest = URLRequest(url: webUrl)

        //web1.scalesPageToFit = true
        web1.isUserInteractionEnabled = true
        web1.scrollView.isScrollEnabled = true
        web1.loadRequest(webRequest)

        // Do any additional setup after loading the view.
    }

Upvotes: 4

Related Questions