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);
}
문제는보기가 나타날 때, 그것은 검은 점이다. 보기를 스크롤 할 때만 단추가 나타납니다.
무엇이 누락 되었습니까? 당신이 다시 그리기 작업을 트리거하지 않는 것처럼
drawrect 또는 createView 끝에 setneedsdisplay를 넣으려고했지만 아무 것도 변경하지 않았습니다. –