У меня есть пользовательское представление, содержащее NSImageView (myImageView) и NSButton (myButton).Когда пользователь изменяет размер окна (используя щелчок мыши и перетаскивая его в нижний правый угол окна), myImageView и myButton автоматически изменяют размер.Но пользовательский вид отличается от оригинального.Как это исправить?Пожалуйста, помогите мне.
Вот мой код:
В appDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
[window makeKeyWindow];
[window setFrameTopLeftPoint:NSMakePoint(0, 576)];
[window setFrame:NSMakeRect(0, 0, 768, 576) display:YES];
[window setBackgroundColor:[NSColor clearColor]];
[window center];
TestView *testView = [[TestView alloc]initWithFrame:NSMakeRect(0, 0, 768, 576)];
[testView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[testView setAutoresizesSubviews:YES];
[window setContentView:testView];}
В TestView.m
- (void)drawRect:(NSRect)dirtyRect {
// Drawing code here.
NSImageView *subView = [[NSImageView alloc]initWithFrame:NSMakeRect(0, 0, 768, 576)];
[subView setImage:[NSImage imageNamed:@"Copenhagen.jpg"]];
[subView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[subView setImageScaling:NSImageScaleProportionallyDown];
[self addSubview:subView];
[subView release];
NSButton *subButton = [[NSButton alloc]initWithFrame:NSMakeRect(70, 100, 100, 40)];
[subButton setTitle:@"Click"];
[subButton setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable|NSViewMaxXMargin|NSViewMaxYMargin|NSViewMinXMargin|NSViewMinYMargin];
[self addSubview:subButton];
[subButton release];
[window setContentView:temp];}
Большое спасибо.