2012-03-23 3 views
0

UIScrollView을 만들었습니다.UICutton이있는 UIScrollView : 스크롤 한 후에 만 ​​버튼이 표시됩니다.

- (void)drawRect:(CGRect)rect, 난 그렇게 내 버튼을 그려했습니다

- (void) createView { 
CGFloat currentY = 0; 
CGFloat currentX = 0; 
CGFloat currentH = 0; 

for (int i = 0; i < [images count]; i++) { 
    UIImage *img = [images objectAtIndex:i]; 

    CGSize cropParam = [[finalCrops objectAtIndex:i] CGSizeValue]; 
    CGSize imgSize = [[finalSizes objectAtIndex:i] CGSizeValue]; 

    UIImage *newImg = nil; 

    if (imgSize.width > 0) { 
     newImg = [img resize:imgSize]; 
    } 

    if (cropParam.width > 0) { 
     newImg = [newImg crop:CGRectMake(0, 0, cropParam.width, cropParam.height)]; 
    } 

    // Create a button for the image 
    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(currentX + margin, 
                    currentY + margin, 
                    newImg.size.width, 
                    newImg.size.height)]; 

    [button setImage:newImg forState:UIControlStateNormal]; 
    [self addSubview:button]; 

    currentX += 2 * margin + newImg.size.width; 

    if (currentX > viewWidth) { 
     currentX = 0; 
     currentY += 2 * margin + newImg.size.height; 
     currentH = newImg.size.height; 
    } 
} 
self.contentSize = CGSizeMake(viewWidth, currentY); 

}

문제는보기가 나타날 때, 그것은 검은 점이다. 보기를 스크롤 할 때만 단추가 나타납니다.

무엇이 누락 되었습니까? 당신이 다시 그리기 작업을 트리거하지 않는 것처럼

답변

0

는 소리 - documentation에서 :

를보기 변경의 실제 내용은, 당신의보기를 다시 그려야 할 때 시스템에 통보하는 것은 귀하의 책임입니다합니다. 뷰의 setNeedsDisplay 또는 setNeedsDisplayInRect : 메서드를 호출하여이 작업을 수행 할 수 있습니다. 이 메서드는 다음 드로잉주기 동안 뷰를 업데이트해야 함을 시스템에 알립니다. 뷰를 업데이트하기 위해 다음 드로잉 사이클 때까지 기다리기 때문에 여러 뷰에서이 메서드를 호출하여 동시에 업데이트 할 수 있습니다.

+0

drawrect 또는 createView 끝에 setneedsdisplay를 넣으려고했지만 아무 것도 변경하지 않았습니다. –

관련 문제