How to Disable all the Links from webView once it is loaded? - swift

I am making simple web based application where I want to disable all the links when the page is loaded fully into the webView and for that I also tried this answer. But when I try this my UIActivityIndicatorView is stopped displaying.
This is my code:
import UIKit
class ViewController: UIViewController,UIWebViewDelegate {
#IBOutlet var webView: UIWebView!
#IBOutlet weak var Activity: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
Activity.hidden = true
var myString = "https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-XID_456"
let myURL = NSURL(string: myString)
let myReq = NSURLRequest(URL: myURL!)
webView.loadRequest(myReq)
webView.delegate = self
}
func webViewDidStartLoad(webView: UIWebView){
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
var activityBarButtonItem = UIBarButtonItem(customView: activityIndicator)
navigationItem.rightBarButtonItem = activityBarButtonItem
activityIndicator.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView){
navigationItem.rightBarButtonItem = nil
}
}
Can anybody tell me how can I achieve that?
Thanks In advance!

What about displaying a transparent view over it?
EDIT
Try adding a new gesture recognizer to it and tell it to do nothing for taps?
let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTouch:"))
recognizer.delegate = self
webView.addGestureRecognizer(newTap)
func handleTouch(recognizer:UIPanGestureRecognizer) {}
Theres a great tut on gestures in swift here Swifty_Gestures

Related

I can't import photos in collection view

Need Help
Hello Guys i am trying to fetch gallary photos to uicollection view but it's show me fatelerror if any one have a solution so please help me
i mark the fatel error plese show it end help me erlier its a very important project for me thank you again advance
Hear is the code
class ADDVC: UIViewController {
//MARK:- Outlets
#IBOutlet weak var IMG_SelectedImageView: UIImageView!
#IBOutlet weak var cameraRollCollectionView: UICollectionView!
//MARK:- variables
var assetCollection: PHAssetCollection!
var photosAsset: PHFetchResult<AnyObject>!
var assetThumbnailSize: CGSize!
//MARK:- Controller Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
let fetchOptions = PHFetchOptions()
let collection:PHFetchResult = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: .some(fetchOptions))
if let first_Obj:AnyObject = collection.firstObject{
//found the album
self.assetCollection = (first_Obj as! PHAssetCollection)
}
//MARK:- Select Photo
tabBarItem.image = UIImage(contentsOfFile: "Plus")
//MARK:- Select Video
}
override func viewWillAppear(_ animated: Bool) {
// Get size of the collectionView cell for thumbnail image
if let layout = self.cameraRollCollectionView!.collectionViewLayout as? UICollectionViewFlowLayout{
let cellSize = layout.itemSize
self.assetThumbnailSize = CGSize(width: cellSize.width, height: cellSize.height)
}
//fetch the photos from collection
self.photosAsset = (PHAsset.fetchAssets(in: self.assetCollection, options: nil) as AnyObject?) as! PHFetchResult<AnyObject>? //HEAR I AM GETTING THE FATEL ERROR
self.cameraRollCollectionView!.reloadData()
}

How to add label and back button to tap gesture viewcontroller in swift

I am using this pod GSImageViewerController for tap gesture.. but i am getting separate view in image with black screen.... but here i need in that black screen back button and name label.. how to add please let me know..
code for tap gesture:
import UIKit
import GSImageViewerController
class ViewController: UIViewController {
#IBOutlet weak var tapImage: UIImageView!
override func viewDidLoad()
{
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
tapImage.isUserInteractionEnabled = true
tapImage.addGestureRecognizer(tapGestureRecognizer)
}
#objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
// let tappedImage = tapGestureRecognizer.view as! UIImageView
let imageInfo = GSImageInfo(image: tapImage.image!, imageMode: .aspectFit)
let transitionInfo = GSTransitionInfo(fromView: tapImage)
let imageViewer = GSImageViewerController(imageInfo: imageInfo, transitionInfo: transitionInfo)
present(imageViewer, animated: true, completion: nil)
}
}
in black image view how to add back button and label.. please suggest me
Instead of using the pod directly download GSImageViewerController.swift and add it to your project. Then you can modify the GSImageViewerController class as per your requirement.

Wkwebview overlying and hiding the toolbar

I am using wkwebview to show a webpage but it is overlaying the toolbar. If I remove
view = webView Then the toolbar can be seen but not the webpage. Been going around in circles with this and tried several possible solutions in other threads but nothing is working. Here is my code...
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate{
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string:"website address")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
}
}

Need help to reload WKWebView from tabbed navigation in Swift

I'm trying to make this reload when a user clicks on the tab. I tried a simple reload but didn't work.
#IBOutlet weak var TabOne: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.google.com")
let urlRequest = URLRequest(url:url!)
TabOne.load(urlRequest)
}
Move the reload code into the viewWillAppear(_:)
as viewDidLoad() will only be called once in the view controller life cycle, while viewWillAppear(_:) will be called every time the view is going to appear on the screen.
This is the code that ended up working.
import UIKit
import WebKit
class FirstViewController: UIViewController {
#IBOutlet weak var TabOne: WKWebView!
override func viewWillAppear(_ animated: Bool) {
let url = URL(string: "https://www.google.com")
let urlRequest = URLRequest(url:url!)
TabOne.load(urlRequest)
}
}

Swift webView empty spaces on scroll

When I'm scrolling up or down and no space for scroll, there are empty spaces. How can I fix it?
Empty places I marked with a red lines.
code
class ViewController: UIViewController {
#IBOutlet weak var webView: UIWebView!
override func viewDidLoad() {
super.viewDidLoad()
let aurl = URL(string: "https://www.google.com")
let arequest = URLRequest(url: aurl!)
webView.loadRequest(arequest)
}
}
I fix it.
webView.scrollView.bounces = false