Resizing WKWebView height on zoom iOS - html

I have a table view where each cell contains a WKWebView of HTML content. Initially the content has its size to fit a prescribed width and height.
What I want to do is allow users to zoom in and out of the WKWebView and while adjusting the height of the cell view.
To give some context what I did was attach a Javascript (WKUserScript) to the WKWebView and in the script it contains
window.onload = function () {
window.webkit.messageHandlers.sizeNotification.postMessage({width:
document.body.scrollWidth, height: document.body.scrollHeight});
}
What this does is when the HTML content is loaded, it will send the message with name "sizeNotification" to a UIViewController conforming to the WKScriptMessageHandler. The message contains the scrollHeight which is what I use to set the frame of the WKWebView by adjusting a height constraint.
I also save that scrollHeight value which will be important later.
After the user zooms in the WKWebView the delegate method scrollViewDidEndZooming gets called which contains the current scaled information of the WKWebView's scrollView. I set the new height constraint constant of the WKWebView's frame by
webViewHeightConstraint.constant = initialHeight * scale
The height of the WKWebView increases and since I used dynamic sizing cells, the table cell height will also adjust accordingly.
That is UNTIL the zoom scale reaches a value close to 1.0
If it gets higher than this value, the content inside the WKWebView/scrollView gets white padding at the bottom.
I suspect that this has to do with the Width/Height ratio of the WebView's frame being changed, since if the initial height of the WebView is greater than content height this will also happen. Another example would be if you open a webpage in Safari that has a content height of 300px but you stretched out the window to have a height of 100px, there would be white space at the bottom (or whatever is set to)
My questions is if there's a fix/workaround for the white bottom padding issue? If you look at an email thread in Mail on iOS you can zoom in and out of the emails and the cell heights adjust accordingly.

Related

Prevent resizing of image

I am trying to show a diagram of products with the image to scale. I have the image element sized with a width and min-width set to the correct width for the image.
I have an 'resize' event listener triggering my zoom on the image element to equal a correction factor:
const ratio = (window.innerWidth / window.outerWidth)
This works acceptably except when the browser vertical sidebar is open.
I searched here and could not find a property to show me sidebar width or to accurately detect zoom level in all browsers. I can use window.devicePixelRatio but that is not working in mac safari.
Would a canvas or svg element offer me some opportunities here i don't see?
Perhaps the best is just to have a input type='range' element next to the image to allow calibration to common object such as a credit card or coin.
Am I mistaken in thinking that if my picture is correct at 600px on my machine that it can be rendered universally in the browser with css width settings?
Thanks alot for any reflections

find out new image width height after browser window resize

i have an image and i have placed markers on it.
problem is that when the browser window resizes, the image size also changes and thus the marker comes to a different position than where it was before.
so, i want to find out the new positions and dimensions of the image after the browser window size changes.
I want to find out the new dimensions of the image, but nothing has worked till now.
i have used clientWidth , offsetWidth, naturalWidth and it all shows the same width before and after the window resize.
(I actually have a zoom property too and it shows the same width even after using zoom), so I am not sure what's wrong?
how do I find out the new image height width and positions after it is zoomed or after the browser window size is changed?
Trigger an event on window resize and find the image height
window.addEventListner("resize",function(){
var img = document.getElementById("img1");
console.log(img.clientWidth);
}

Qt - How to make QTextBrowser resize to contents (vertical layout)

I have a QTextBrowser object in my dialog which will have HTML written to it. It is in a vertical layout with several other objects. I have the vertical size policy currently set to MinimumExpanding for this QTextbrowser. The problem is if the HTML written to the browser ends up taller than the QTextBrowser's minimum set height, its height stays the same and it instead makes me scroll down through the browser to see all the data, where I would like it instead to show all the data at once. I have tried changing around the size policies for the QTextBrowser and the layout it is in, but nothing I have tried has worked. Is there a way to do this that I am overlooking?
QTextBrowser *m_text=new QTextBrowser;
m_text->setFixedHeight(m_text->document()->size().height());
wish to help you.
If you know how many lines you are going to add then you can work out a height and then set that height.
int number_of_lines; // If you can get this value from somewhere this should work
// Get the height of the font being used
QFontMetrics font_metrics(ui->text_browser->font());
int font_height = font_metrics.height();
// Get the height by multiplying number of lines by font height, Maybe add to this a bit for a slight margin?
int height = font_height * number_of_lines;
// Set the height to the text broswer
ui->text_browser->setMinimumHeight(height);
ui->text_browser->setMaximumHeight(height);

HTML CSS Horizontal Layout Scaling

I'm trying to make a horizontal layout (with columns) where the content scales based on the browser window height.
I came across answers about perfect ratio based on width, but I want to have an infinite width (as the amount of content won't always be the same).
Is this possible just using HTML/CSS?
It is going to be hard to maintain the aspect ratio with css, but if you set the height of the maincontent box to 90% and the height of the containers to 100%. They should respond to
the browser window. But only in height, never in width.
From there you can use javascript to set the with to be <height> * 1.5 (or similar) you will have to do this in the document ready event, but also in the window resize event.

What is difference between UIModalTransitionStyle and UIModalPresentationStyle?

For UIViewController, we have UIModalTransitionStyle and UIModalPresentationStyle
Question is what is the difference of them ?
UIModalTransitionStyle is used to specify how the modal form transitions into view. For example, it can come in vertically, flip horizontal, or do a partial curl.
UIModalPresentationStyle is used to specified whether you want the modal form to be full screen (basically what iPhone uses) or otherwise (therefore only makes sense for iPad) as a page sheet (full height, width is the size of the portrait mode screen width), a form sheet (partial width and partial height) or current context (i.e. what the parent container uses).