How do you bring normal control into NSView?
What I'm actually trying to do is put the WebKitView in a ScreenSaver (which inherits from NSView). I am completely new to MacOS X and Cocoa (but I am very familiar with Objective-C and have used some parts of GNUStep). Do I need to pave? I only want to show one control in the whole NSView.
a source to share
In initWithFrame:isPreview:
, create a WebView in the usual way , then send a message addSubview:
passing the webview :
webView = [[WebView alloc] initWithFrame:frame];
[self addSubview:webView];
If you're wondering which rectangle you should pass as a WebView frame, read the View Programming Guide . Also, don't forget to release webView
to dealloc
(or save it to initWithFrame:isPreview:
).
Once you have a web view, you will need to load a page into it. Set a suitable long animation interval (at least a couple of seconds) and load the page in animateOneFrame
:
- (void) animateOneFrame {
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com/"]]];
}
You can also handle WebViewProgressFinishedNotification
and defer reloading the webview until it happens (to compensate for slow or saturated connections). You will do this with an instance variable that you set in YES
both initWithFrame:isPreview:
the notification handler method and then inspect and set NO
to animateOneFrame
:
- (void) animateOneFrame {
if (hasFinished) {
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com/"]]];
hasFinished = NO;
}
}
a source to share