我将一个按钮和一个图像分配到相同的位置 (0, 0),但它们绘制在不同的位置。为什么会这样?
这是我的代码:
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
[window makeKeyWindow];
[window setFrame:NSMakeRect(0, 0, 500, 468) display:YES];
//[window setFrame:[[NSScreen mainScreen]frame] display:YES];
[window setBackgroundColor:[NSColor clearColor]];
[window center];
[[window contentView] setAutoresizesSubviews:YES];
NSImageView *subView = [[NSImageView alloc]initWithFrame:NSMakeRect(0, 0, 500, 468)];
[subView setImage:[NSImage imageNamed:@"Flowers.jpg"]];
[subView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[subView setAutoresizesSubviews:YES];
NSButton *subButton = [[NSButton alloc]initWithFrame:NSMakeRect(0, 0, 100, 40)];
[subButton setTitle:@"testing"];
[subButton setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable|NSViewMaxXMargin|NSViewMaxYMargin|NSViewMinXMargin|NSViewMinYMargin];
[subView addSubview:subButton];
[window setContentView:subView];
}
这是构建后的结果: