Post

Replies

Boosts

Views

Activity

WKWebView layout problem when tap in a form input
I have a simple ViewController with a WKWebView, the page renders ok and there is no problem at first. This is the code: import WebKit class SignIWkWebViewViewController: UIViewController {      var wkWebView: WKWebView!    override func loadView() {      let webConfiguration = WKWebViewConfiguration()      wkWebView = WKWebView(frame: .zero, configuration: webConfiguration)      view = wkWebView    }      override func viewDidLoad() {      super.viewDidLoad()      startLoad()    }        // Receive Transfer Details and Results with a Delegate    private lazy var session: URLSession = {      let configuration = URLSessionConfiguration.default      configuration.waitsForConnectivity = true      return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)    }()        var receivedData: Data?        private func startLoad(){      print("\(type(of: self)) \(#function)")            guard let url = URL(string:"https://itunesconnect.apple.com/login") else { fatalError("Can not get url") }            receivedData = Data()      let task = session.dataTask(with: url)      task.resume()    }        private func handleClientError(_ error: Error){      print("Error: \(error)")    } }     extension SignIWkWebViewViewController : URLSessionDataDelegate{  func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {     print("\(type(of: self)) \(#function)")      guard let response = response as? HTTPURLResponse,        (200...299).contains(response.statusCode),        let mimeType = response.mimeType,        mimeType == "text/html" else {        completionHandler(.cancel)        return      }      completionHandler(.allow)    }    func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {      print("\(type(of: self)) \(#function)")      self.receivedData?.append(data)    }    func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {       print("\(type(of: self)) \(#function)")      DispatchQueue.main.async {        //self.loadButton.isEnabled = true        if let error = error {          self.handleClientError(error)        } else if let receivedData = self.receivedData,          let string = String(data: receivedData, encoding: .utf8) {          self.wkWebView.loadHTMLString(string, baseURL: task.currentRequest?.url)        }      }    } } The issue start when I tap in the form field in the web page. I set a breakpoint for UIViewAlertForUnsatisfiableConstraints expr -l objc++ -O -- [[UIWindow keyWindow] autolayoutTrace] And I got this error: UIWindow:0x7f9ed2d05d40 |  UITransitionView:0x7f9ed2c110f0 |  |  UIDropShadowView:0x7f9ed2e071c0 |  |  |  WKWebView:0x7f9ed3027e00'iTunes Connect' |  |  |  |  WKScrollView:0x7f9ed3827800 |  |  |  |  |  WKContentView:0x7f9ed382f800 |  |  |  |  |  |  UIView:0x7f9ed2c0a240 |  |  |  |  |  |  |  UIView:0x7f9ed2c067a0 |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2d13760 |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed501d6c0 |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed500cfd0 |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed50063c0 |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed501d830 |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c18210 |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c107a0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKChildScrollView:0x7f9ed3081200 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c14a30 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c19810 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c10910 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c17dc0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c19560 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed500f3f0 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIView:0x7f9ed500f590 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed5019150 |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  |  UIView:0x7f9ed50177d0 |  |  |  |  |  |  |  |  |  |  |  |  WKCompositingView:0x7f9ed2c0fd20 |  |  |  |  |  |  UILayerHostView:0x7f9ed2d09100 |  |  |  |  |  UIView:0x7f9ed5007fd0 |  |  |  |  |  |  UITextSelectionView:0x7f9ed501bbd0 |  |  |  |  |  |  UIHighlightView:0x7f9ed2e0b7f0 |  |  |  |  |  UIScrollViewScrollIndicator:0x7f9ed2e0ad40 |  |  |  |  |  |  UIView:0x7f9ed2e0b680 |  |  |  |  |  _UIScrollViewScrollIndicator:0x7f9ed2e0bb30 |  |  |  |  |  |  UIView:0x7f9ed2e0bcd0 Legend:- is laid out with auto layout + - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES • - layout engine host What is wrong in the code?
Topic: Safari & Web SubTopic: General Tags:
0
0
1.3k
Jul ’20
DownSampling / Scaling Image Quality. UIImage versus ImageIO
I have been doing some tests with the code to DownSampling / Scaling Image an Image from WWDC18 Session 416 iOS Memory Deep Dive.In this session they said that: - "Memory use if related the DIMENSION of the image, NOT file size.” - UIImage is expensive for sizing and resizing (will decompress memory first, internal coordinate space transforms are expensive) - Use ImageIO, it will work with out dirty memory (also API is faster)For my tests I used High Resolution Images with dimensions:1920 × 1080, 2560 × 1600, 3840 × 2160, 2560 × 1600, 4712 × 3133, 2560 × 1600 and 3072 × 2048.The following is the code that I used.import UIKit struct ImageConverter{ static func resize(image: UIImage)-> UIImage{ let size = CGSize(width: 300, height: 300) let renderer = UIGraphicsImageRenderer(size: size) let resizedImage = renderer.image { context in image.draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height)) } return resizedImage } }import UIKit import ImageIO struct ImageIOConverter{ static func resize(url: URL)-> UIImage{ guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil) else { fatalError("Can not get imageSource") } let options: [NSString: Any] = [ kCGImageSourceThumbnailMaxPixelSize: 300, kCGImageSourceCreateThumbnailFromImageAlways: true ] guard let scaledImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, options as CFDictionary) else { fatalError("Can not get scaledImage") } return UIImage(cgImage: scaledImage) } }import UIKit class ViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! // Constraints Width: 300, Height: 300 let resource = "1" let ext = ".jpg" var imageNamed : String { return resource + ext } @IBAction func uploadOriginalImage(_ sender: Any) { guard let image = UIImage(named: imageNamed) else { fatalError("Can not get image") } imageView.image = image } @IBAction func uploadImageScaledUsingUIImage(_ sender: Any) { guard let image = UIImage(named: imageNamed) else { fatalError("Can not get image") } imageView.image = ImageConverter.resize(image: image) } @IBAction func uploadImageUsingImageIO(_ sender: Any) { guard let url = Bundle.main.url(forResource:resource, withExtension: ext) else { fatalError("Can not get image url") } imageView.image = ImageIOConverter.resize(url: url) } }Effectively, I found that with ImageIO, the amount of memory is smaller, but at the same time I also noticed that using ImageIO the final image look to have lower quality than using UIImage.I mean, using UIImage the final image looks more to the original image than using ImageIO.I wonder if, Is this the expected result? (Lower image quality but also lower memory).
1
0
5.5k
Oct ’18