iOS Question Rescale IOS Webview

Derek Johnson

Active Member
Licensed User
Longtime User
Is there an equivalent method for B4I to set the scale of a Webview like this in B4A?

B4X:
Obj1.Target = WvMain
Obj1.RunMethod2("setInitialScale", "200", "java.lang.int")

Derek
 

Derek Johnson

Active Member
Licensed User
Longtime User
JanPro, thanks for you code.

B4X:
Dim NaObj As NativeObject = WebView1
NaObj.GetField("scrollView").SetField("zoomScale",1.50)

I tried that but I had a problem where the zoom level set seemed to be with regard to the current view, that itself was already scaled.

After some research the sub I used was this:

B4X:
Sub SetZoom(ThisView As WebView,ZoomLevel As Float)

    If ThisView.IsInitialized Then
   
        Dim NaObj As NativeObject = ThisView
        Dim z, minimumZoomScale, maximumZoomScale As Float   
        minimumZoomScale=NaObj.GetField("scrollView").GetField("minimumZoomScale").AsNumber
        maximumZoomScale=NaObj.GetField("scrollView").GetField("maximumZoomScale").AsNumber
        If ZoomLevel=-1 Then
            z=1.0
        Else
            z=ZoomLevel*minimumZoomScale
            z=Min(z,maximumZoomScale)
        End If
        Log("Setting relative zoom level to " & z)

        NaObj.GetField("scrollView").SetField("zoomScale",z)
       
    End If
End Sub

This code still has an issue though; when I execute SetZoom, the display scales correctly but it does not cause a re-draw.
Hence the Webview looks blurry. Moving the display by hand causes it to re-draw at full resolution.

So my next question is, how do I force the Webview to re-draw. I've seen some discussion of this and even a solution proposed using this code here:

http://stackoverflow.com/questions/17257629/force-uiwebview-to-redraw

using this code

B4X:
- (void) forceRedrawInWebView:(UIWebView*)webView {
    NSArray *views = webView.scrollView.subviews;

    for(int i = 0; i<views.count; i++){
        UIView *view = views[i];

        //if([NSStringFromClass([view class]) isEqualToString:@"UIWebBrowserView"]){
            [view setNeedsDisplayInRect:webView.bounds]; // Webkit Repaint, usually fast
            [view setNeedsLayout]; // Webkit Relayout (slower than repaint)

            // Causes redraw & relayout of *entire* UIWebView, onscreen and off, usually intensive
            [view setNeedsDisplay];
            [view setNeedsLayout];
            // break; 
        //}
    }
}

but how do I invoke forceRedrawInWebView from B4I?

Derek
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
I think that the re-draw is happening now but it hasn't made any difference to the appearance of the Webview. It still needs to be manually pinched to get the text to look sharp. :-(

Has anyone experienced this issue after changing the zoom scale? This can still happen when the zoom level is 1.0. I'm wondering if there are two copies a pixel apart.
 
Upvote 0

narek adonts

Well-Known Member
Licensed User
Longtime User
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
I tried Narek's suggestion as well as the re-draw. Neither fixed the issue unfortunately.

I've attached an image of the out of focus screen, plus a zipped copy of my entire test app.

Derek
 

Attachments

  • Screen.PNG
    Screen.PNG
    92.9 KB · Views: 288
  • Webtest.zip
    7.2 KB · Views: 213
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Narek - that's brilliant thanks so much!

Just to recap this sub works now:

B4X:
Sub SetZoom(ThisView As WebView,ZoomLevel As Float)

    If ThisView.IsInitialized Then
  
        Dim NaObj As NativeObject = ThisView
        Dim z, minimumZoomScale, maximumZoomScale As Float  
        minimumZoomScale=NaObj.GetField("scrollView").GetField("minimumZoomScale").AsNumber
        maximumZoomScale=NaObj.GetField("scrollView").GetField("maximumZoomScale").AsNumber
        If ZoomLevel=-1 Then
            z=1.0
        Else
            z=ZoomLevel*minimumZoomScale
            z=Min(z,maximumZoomScale)
        End If
        Log("Setting relative zoom level to " & z)
        NaObj.GetField("scrollView").RunMethod("setZoomScale:animated:",Array(z,True))  
        'NaObj.GetField("scrollView").SetField("zoomScale",z) 'Didn't update till manual screen change
      
    End If
End Sub

No need for screen refresh now!
 
Last edited:
Upvote 0
Top