Re: Creating WebView in code
Re: Creating WebView in code
- Subject: Re: Creating WebView in code
- From: "Adam R. Maxwell" <email@hidden>
- Date: Fri, 02 Apr 2010 18:46:23 -0700
On Apr 2, 2010, at 2:08 PM, Nick Zitzmann wrote:
>
> On Apr 2, 2010, at 2:19 PM, Jenny M wrote:
>
>> D'oh, you told me that before and I completely forgot. So I tried
>> that, but the page still appears blank. I don't want the page to be
>> visible so I didn't set makeKeyOrderFront.
FWIW, I'm able to draw WebView content to a bitmap without involving an offscreen window at all, so I'm not sure what problem Nick ran into with that. One thing that's bitten me is that you need to force layout if you send setAllowsScrolling:NO to the WebFrameView.
> There's one more thing. WebView loads requests asynchronously, so you need to block while it is loading the request and laying out the page while taking some time out to run the run loop. So do something like this:
>
> while ([myWebView isLoading])
> {
> NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>
> [myWebView setNeedsDisplay:NO];
> [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate dateWithTimeIntervalSinceNow:1.0] inMode:NSDefaultRunLoopMode dequeue:YES];
> [pool drain];
> }
> [webView setNeedsDisplay:YES];
>
> When this loop is done, any print operation you perform on the web view ought to work.
Just be careful if you use this with any redirects, since -isLoading will return NO, then a moment later return YES again. That shouldn't matter loading from a file, but it was very tedious to deal with for creating thumbnails from web pages (you have to track redirected frames manually).
--
Adam
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden