2014-02-15 10 views
0

NSSplitView 안에 포함 된 상당히 간단한 사용자 정의 뷰 클래스가 있습니다. 그 뷰 클래스는 NSMatrix와 몇 개의 더미 셀을 추가하여 그 자체를 채 웁니다. 정말 이상한 점은 슈퍼 뷰를 채울만한 크기가 있음에도 불구하고 사실 슈퍼 뷰보다 훨씬 크고 넓습니다. 나는 프레임과 범위를 기록하려고했는데, 그 결과도 아래에있다.하지만 나는 혼란 스럽다. 내가 기대했던대로이 작품의 크기가 슈퍼 뷰가 아닌 이유는 무엇일까요?범위 바깥 쪽 NSMatrix 드로잉

Launches like this Looks like this when I resize

- (id)initWithFrame:(NSRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     NSImageCell *prototypeCell = [[NSImageCell alloc] init]; 
     [prototypeCell setBordered:YES]; 

     _matrix = [[NSMatrix alloc] initWithFrame:self.bounds 
              mode:NSHighlightModeMatrix 
             prototype:prototypeCell 
            numberOfRows:1 
            numberOfColumns:1]; 

     [_matrix setCellSize:NSMakeSize(50, 50)]; 

     [_matrix setBackgroundColor:[NSColor redColor]]; 
     _matrix.drawsBackground = YES; 

     [_matrix addRow]; 

     NSCell *cell = [_matrix cellAtRow:0 column:0]; 
     [cell setImage:[NSImage imageNamed:@"block.png"]]; 

     cell = [_matrix cellAtRow:1 column:0]; 
     [cell setImage:[NSImage imageNamed:@"block.png"]]; 

     [self addSubview:_matrix]; 

     NSLog(@"%@", NSStringFromRect(self.bounds)); 
     NSLog(@"%@", NSStringFromRect(self.frame)); 
     NSLog(@"%@", NSStringFromRect(_matrix.bounds)); 
     NSLog(@"%@", NSStringFromRect(_matrix.frame)); 
    } 
    return self; 
} 

Output: 
2014-02-15 15:16:23.458 Temp[5970:303] {{0, 0}, {45, 331}} 
2014-02-15 15:16:23.459 Temp[5970:303] {{500, 0}, {45, 331}} 
2014-02-15 15:16:23.459 Temp[5970:303] {{0, 0}, {45, 331}} 
2014-02-15 15:16:23.459 Temp[5970:303] {{0, 0}, {45, 331}} 

답변

0

당신은 부모 뷰의 가장자리에 부착하여 매트릭스를 유지하기 위해 자동 레이아웃 제약 또는 구식 스프링-N-스트럿 중 하나를 설정하지 않은 .

당신이 상태 복원을 실행하고있는 중입니다. 따라서 실행시 부모보기가 한 크기로 생성되고 상태가 복원되고 창/splitView의 크기가 조정되고 하위보기가 상위와 더 이상 일치하지 않습니다.

일반적으로 직접보기를 만드는 경우 제약 조건을 즉시 추가하거나 자동 레이아웃을 사용하지 않는 경우 -setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable (이 경우)을 호출하십시오.

+0

당신은 절대적으로 맞습니다. 저는 다른 문제를 쫓아 내려고 노력했지만, 다시 삽입하는 것을 잊었습니다. 고마워요! – XeroxDucati