How to calculate the correct size to zoom a WebView?
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];
}
精彩评论