WebView cannot scroll from top to bottom of the webpage - ios

I have loaded a webpage to xcode WebView. But only the upper portion of the page is loaded. I can not scroll down to the bottom of the page. Same fact for pdf. Only upper 2 pages can be scrolled. What can i do ?Here is my code.
Thanks in advance.
import UIKit
class ViewController: UIViewController {
#IBOutlet var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
var URL = NSURL(string: "http://www.archetapp.com")
webView.loadRequest(NSURLRequest(URL: URL!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//for pdf
import UIKit
class ViewController: UIViewController {
#IBOutlet var webViews: UIWebView!
var path = ""
override func viewDidLoad() {
super.viewDidLoad()
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
self.webViews.loadRequest(NSURLRequest(URL: url!))
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}

Try this!
import UIKit
class ViewController: UIViewController, UIWebViewDelegate {
#IBOutlet var webView : UIWebView
override func viewDidLoad() {
super.viewDidLoad()
//load initial
path = NSBundle.mainBundle().pathForResource("ibook", ofType: "pdf")!
let url = NSURL.fileURLWithPath(path)
var req = NSURLRequest(URL : url)
webView.delegate = self // <---
webView.loadRequest(req)
}
func webViewDidStartLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = true
println("webViewDidStartLoad")
}
func webViewDidFinishLoad(webView : UIWebView) {
//UIApplication.sharedApplication().networkActivityIndicatorVisible = false
webViews.scalesPageToFit = true
webViews.scrollView.scrollEnabled = true
webViews.userInteractionEnabled = true
println("webViewDidFinishLoad")
}
}

I had the same issue just today and at least in my case it was caused by having the "Scale Pages to Fit" option checked in the WebView properties. I'm assuming Carlos' reply regarding the zoom scale fixes it anyways but I didn't need the option enabled in the first place so that was my easy fix.

Related

How to open Facebook and Twitter share buttons when clicking on it in a WKWebView(swift 3)?

I am actually using a WKWebView in my IOS application. The url loaded successfully but when clicking on the Facebook and Twitter share buttons nothing happens. How can I solve this issue?
Here is the following code:
ViewController:
import UIKit
import WebKit
class ViewController: UIViewController,WKNavigationDelegate {
#IBOutlet var containerView : UIView! = nil
var webView = WKWebView()
override func loadView() {
super.loadView()
self.webView = WKWebView()
self.view = self.webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = NSURL(string: "https://www.examplepage.com")!
webView.load(NSURLRequest(url: url as URL) as URLRequest)
webView.allowsBackForwardNavigationGestures = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

UIWebView UIViewController does not load URL

I am currently having this issue with IOS app.
When I click on a URL button the UIWebView loads the correct URL in first instance however when I visit another page within same Web View Frame it stores that page to its memory. When I navigate to another button and click back to previous button it shows the page that I was previously in instead of loading the URL.
What I want to achieve is when user clicks on button the UIWebView loads the URL .
My current code:
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
You can use following code it will work.
import UIKit
class MenuViewController: UIViewController {
#IBOutlet weak var oyebWebView: UIWebView!
override func viewWillAppear(animated: Bool) {
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
}
override func viewDidLoad() {
// super.viewDidLoad()
//super.viewWillAppear(YES)
// self.viewDidAppear(true)
let webUrl : NSURL = NSURL(string: MenuUrl)!
let webRequest : NSURLRequest = NSURLRequest(URL: webUrl)
oyebWebView.loadRequest(webRequest);
//oyebWebView.loadRequest(NSURLRequest(URL: NSURL(string: MenuUrl)!))
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

XCODE swift - webview can't open ics link - in safari it works

I've made in Swift a webview & in that webview there are links to ics file on the same domain of the webview. Now, when you click this link in Safari, you can perfectly add this to your calendar, but when I try this in iOS simulator, or on my device, I can't 'open' the ICS file link.
Any idea what I am doing wrong? Thanks!
This is my code:
import UIKit
class FirstViewController: UIViewController {
#IBOutlet weak var webAgenda: UIWebView!
#IBOutlet weak var activityagenda: UIActivityIndicatorView!
var url = "http://******.be/agenda.php"
func loadURL () {
let requestURL = NSURL(string: url)
let request = NSURLRequest(URL: requestURL!)
webAgenda.loadRequest(request)
}
override func viewDidLoad() {
super.viewDidLoad()
loadURL()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func webViewDidStartLoad(webView: UIWebView) {
activityagenda.hidden = false
activityagenda.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView) {
activityagenda.hidden = true
activityagenda.stopAnimating()
}
because you load a http site so in iOS9 will have problem with App Transport Security.
disable ATS here

How to make a browser with UIWebView?

I have been trying to make a web browser in Swift and it has not been going well.
I was wondering why I got errors whenever I typed webView.delegate = self.
import UIKit
class MapViewController: UIViewController {
#IBOutlet weak var searchBar: UISearchBar!
#IBAction func back(sender: AnyObject) {
webView.goBack()
}
#IBOutlet weak var menuButton:UIBarButtonItem!
#IBOutlet weak var webView: UIWebView!
func searchBarSearchButtonClicked(searchBar: UISearchBar!) {
searchBar.resignFirstResponder()
var text = searchBar.text
var url = NSURL(string: text) //type "http://www.apple.com"
var req = NSURLRequest(URL:url!)
self.webView!.loadRequest(req)
}
override func viewDidLoad() {
super.viewDidLoad()
//problem here
webView.delegate = self;
webView.keyboardDisplayRequiresUserAction = true
//problem down here
webView.frame = self.view.frame;
let url = NSBundle.mainBundle().URLForResource("index", withExtension:"html")
let request = NSURLRequest(URL: url!)
webView.loadRequest(request)
// var url = NSURL(string:"http://www.google.com")
// var req = NSURLRequest(URL:url!)
// self.webView!.loadRequest(req)
self.searchBar.delegate = self
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
You are assigning self as the delegate, but your class does not implement the UIWebViewDelegate protocol.
class MapViewController: UIViewController, UIWebViewDelegate {

swift uiwebview is nil

some disapointement with uiwebview, for very simple code
class ViewController: UIViewController {
#IBOutlet weak var mavue: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let requestURL = NSURL(string: "http://www.google.com")
let request = NSURLRequest(URL: requestURL!)
mavue?.loadRequest(request)
println("myWebView : \(mavue)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
println("myWebView : (mavue)") return nil
i try it on simulator, i have loaded my controllerview from presentViewController maybe it's the reason why?
but my code doesn't show mywebview.
mywebView is connected to my IBoutlet
thank
EDIT : It 's work, I think that th mistake was to keep the default uiviewcontroller , when i use a subclass all is ok
Thank

Resources