开发者

How to calculate the correct size to zoom a WebView?

开发者 https://www.devze.com 2023-02-14 08:09 出处:网络
I have a WebView in my window. When the user cli开发者_StackOverflowcks on the Zoom button (the green button on the top left of the window), I want to change the size of the window such that the WebVi

I have a WebView in my window. When the user cli开发者_StackOverflowcks on the Zoom button (the green button on the top left of the window), I want to change the size of the window such that the WebView is just large enough to show the web page, as recommended in the Mac HCI guidelines.

Question is: how to I go about calculating the size of the WebView to zoom to?

Thanks.


Oh sorry, then you should reverse it :)

- (IBAction)resizeToView:(id)sender
{
    // webview content sub/document-view
    NSView *docView =[[[webView mainFrame] frameView] documentView]; 
    NSRect docRect = [docView frame];

    // height and width
    int height = docRect.size.height;
    int width = docRect.size.width;

    NSRect frame = [window frame];
    int delta = height - frame.size.height;

    // y/height
    frame.origin.y -= delta;
    frame.size.height += delta;

    // x/width
    frame.size.width = width; 

    [window setFrame:frame display:YES]; 
}
0

精彩评论

暂无评论...
验证码 换一张
取 消