开发者

Change WebView position Cocoa

I'm quite a newbie to Cocoa & Mac programming. I have a WebView and I want to move it. Is there a way to change the coordinates of the WebView?

EDIT: Some relevant code: NistractAppDelegate.m

#import "NistractAppDelegate.h"

@implementation NistractAppDelegate

@synthesize window;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    [window setAlphaValue:0];
    [window setBackgroundColor:[NSColor colorWithCalibratedRed:0.125490196078431 green:0.125490196078431 blue:0.125490196078431 alpha:1]];
    [mainWebView setBackgroundColor:[NSColor colorWithCalibratedRed:0.125490196078431 green:0.125490196078431 blue:0.125490196078431 alpha:1]];
    [[mainWebView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
    mainWebView.frame = NSMakeRect(mainWebView.frame.origin.x + 10, mainWebView.frame.origin.y, mainWebView.frame.size.width, mainWebView.frame.size.height);

    [window makeKeyAndOrderFront:self];
    [[window animator] setAlphaValue:1];


}

开发者_JAVA百科@end

NistractAppDelegate.h

#import <Cocoa/Cocoa.h>

@interface NistractAppDelegate : NSObject <NSApplicationDelegate> {
    NSWindow *window;
    IBOutlet NSView *mainView;
    IBOutlet id mainWebView;
}

@property (assign) IBOutlet NSWindow *window;

@end


If you just want to move the entire webview you need set it's frame.

WebView.frame = NSMakeRect(x,y,width,height);

Eg if you want to just shift it left by ten pixels:

WebView.frame = NSMakeRect(WebView.frame.origin.x + 10, WebView.frame.origin.y, WebView.frame.size.width, WebView.frame.size.height);

When in doubt always you look in the documentation, which you can do from within side XCode, by selecting some text and right clicking then selecting Find Text In Documentation

Or use Google by searching "{Class name} class reference" Eg "nsview class reference"

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜