Ответ 1
Вы можете зарегистрироваться в качестве делегата загрузки фрейма WebView
, а при загрузке страницы вы можете запросить представление документа основного кадра для его размера и изменить размер WebView
. Убедитесь, что вы отключили полосы прокрутки на кадре или у вас возникнут проблемы.
Имейте в виду, что некоторые страницы могут быть очень большими, когда я тестировал daringfireball.net, он пришел на высоту 17612 пунктов, что явно слишком велико для отображения на экране.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
//set ourselves as the frame load delegate so we know when the window loads
[webView setFrameLoadDelegate:self];
//turn off scrollbars in the frame
[[[webView mainFrame] frameView] setAllowsScrolling:NO];
//load the page
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://daringfireball.net"]];
[[webView mainFrame] loadRequest:request];
}
//called when the frame finishes loading
- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)webFrame
{
if([webFrame isEqual:[webView mainFrame]])
{
//get the rect for the rendered frame
NSRect webFrameRect = [[[webFrame frameView] documentView] frame];
//get the rect of the current webview
NSRect webViewRect = [webView frame];
//calculate the new frame
NSRect newWebViewRect = NSMakeRect(webViewRect.origin.x,
webViewRect.origin.y - (NSHeight(webFrameRect) - NSHeight(webViewRect)),
NSWidth(webViewRect),
NSHeight(webFrameRect));
//set the frame
[webView setFrame:newWebViewRect];
//NSLog(@"The dimensions of the page are: %@",NSStringFromRect(webFrameRect));
}
}