Below are two depictions of a WKWebView displaying text from Act 2, Scene 1, of a play. The depiction to the right is after a tap gesture summons, at the top, both a status bar and a navigation bar (which includes a back arrow to the table of contents and text size controls) and, at the bottom, a toolbar with arrows, one to show the previous scene (Act 1, Scene 3) and one to show the next scene (Act 2, Scene 2).
Everything apparently was working fine. But after I recently upgraded to Xcode 9.0.1 (and from Swift 3 to Swift 4), the navigation system in the (bottom) toolbar no longer functions in my iPhone 6 running iOS 11.0.3 (THOUGH everything WORKS FINE in the SIMULATOR (iPhone 6 / iOS 11.0)) and now responds as if a tap gesture were being made in the middle of the view away from the (bottom) toolbar, whereas before the (bottom) toolbar was properly unresponsive to any touches except on the left-pointing and right-pointing triangles to change the scenes. The status bar and the navigation bar still behave as desired as before.
I created the (bottom) toolbar programmatically and thought I had to bring it in front of the WKWebView to get it to work. Here is what I've tried to fix this:
self.view.bringSubview(toFront: toolbar!)
But that did not work. And I tried:
toolbar!.layer.zPosition = 1
But neither did that work. Someone suggested that the problem might be related to the "safe area" in iOS 11, but I am unsure how to address that. I would appreciate your kind help.
Here is the function that creates the (bottom) toolbar:
// Create (bottom) toolbar and items (buttons and text).
func createToolbar() {
let frame = CGRect(x: 0, y: UIScreen.main.bounds.size.height-44, width: UIScreen.main.bounds.size.width, height: 44)
toolbar = UIToolbar(frame: frame)
toolbar?.sizeToFit()
toolbar?.isHidden = true
triangleLeftButton = UIBarButtonItem(image: UIImage(named: "triangleLeft_15x20"), style: .plain, target: self, action:#selector(showPrevious))
triangleLeftText = UIBarButtonItem(title: "\(String(describing: "previous"))", style: .plain, target: nil, action: nil)
let flexibleSpacer = UIBarButtonItem(barButtonSystemItem:.flexibleSpace , target: self, action: nil)
triangleRightText = UIBarButtonItem(title: "\(String(describing: "next"))", style: .plain, target: nil, action: nil)
triangleRightButton = UIBarButtonItem(image: UIImage(named: "triangleRight_15x20"), style: .plain, target: self, action:#selector(showNext))
if (triangleLeftText?.isEqual(""))! {
triangleLeftButton?.isEnabled = false
} else if (triangleRightText?.isEqual(""))! {
triangleRightButton?.isEnabled = false
}
var items = [UIBarButtonItem]()
items.append(triangleLeftButton!)
items.append(triangleLeftText!)
items.append(flexibleSpacer)
items.append(triangleRightText!)
items.append(triangleRightButton!)
toolbar?.items = items
self.view.addSubview(toolbar!)
// self.view.bringSubview(toFront: toolbar!)
// toolbar!.layer.zPosition = 1
// Set colors for toolbar items and for toolbar:
toolbar?.tintColor = UIColor(red: 0.5, green: 0.0, blue: 1.0, alpha: 1.0) //purple for toolbar items
toolbar?.barTintColor = UIColor.white //white for toolbar color
}