NSCollectionView
에 약간의 자극이 있으며 창을 스크롤 할 때 NSCollectionViewItem
이 시각적으로 깨집니다.스크롤 할 때 NSCollectionView를 다시 그리면 그래픽이 깨집니다.
균열의 비율은 스크롤 속도에 따라 다릅니다. 예를 들어, 천천히 스크롤하면 해체가 더 자주 발생합니다. 빠른 속도로 스크롤합니다. 이 문제는 내가 사용하고있는 NSCollectionViewItem
의 사용자 지정 NSView가 볼 수있는 프레임의 경계를 넘어서는 것처럼 보입니다.
내 NSView (사용자 정의보기 NSCollectionViewItem
)는 매우 간단한 그리기 알고리즘을 가지고 있습니다. 너무 복잡하지 않습니다. 본질적
그 안에 몇 프레임을의 drawRect 방법의 dirtyRect 내의 프레임을 생성하고 생성 : I는 그래픽 포커스를 잠그고 전에 해제 및 코드 후뿐만 아니라 설정 시도
-(void)drawRect:(NSRect)dirtyRect
{
NSRect mOuterFrame = NSMakeRect(dirtyRect.origin.x, dirtyRect.origin.y, 104, 94);
NSRect mSelectedFrame = NSInsetRect(mOuterFrame, 2, 2);
NSRect mRedFrame = NSInsetRect(mSelectedFrame, 2, 2);
NSRect mInnerFrame = NSInsetRect(mRedFrame, 2, 2);
NSBezierPath * mOuterFramePath = [NSBezierPath bezierPathWithRect:mOuterFrame];
NSBezierPath * mSelectedFramePath = [NSBezierPath bezierPathWithRect:mSelectedFrame];
NSBezierPath * mRedFramePath = [NSBezierPath bezierPathWithRect:mRedFrame];
NSBezierPath * mInnerFramePath = [NSBezierPath bezierPathWithRect:mInnerFrame];
[mainBackgroundColor set];
[mOuterFramePath fill];
if (selected)
[[NSColor yellowColor] set];
else
[mainBackgroundColor set];
[mSelectedFramePath fill];
if (isRedBorder)
[[NSColor redColor] set];
else
[mainBackgroundColor set];
[mRedFramePath fill];
[[NSColor blackColor] set];
[mInnerFramePath fill];
}
컨텍스트와 복원 - 아무도 문제를 해결하지 못하는 것 같습니다.
스노우 레오파드를 사용하고 있습니다. 차이가 있다고 생각하지 않습니다. NSResponder에 추천 여기에 관심있는 사람들을위한
솔루션 업데이트
이 문제에 대한 솔루션입니다. 나는 방법 dirtyRect
을 기반으로 초기 mOuterFrame
을 만들었으며, 이는 잘못된 것으로 알고 있습니다.
NSRect mOuterFrame = NSMakeRect(dirtyRect.origin.x, dirtyRect.origin.y, 104, 94);
0 기반의 개시 지점에 :에서 빠른 변화 위의 코드를 변경하지만 제안
NSRect mOuterFrame = NSMakeRect(0, 0, 104, 94);
는 또한, 난 단지 사각형을 사용하고 같이있는 코드의 효율성을 쥐게 그 자체로 문제를 해결하기에 충분했다. 2 픽셀 줄을 얻기 위해 변경 사항을 추가해야했습니다. 새로운 방법 : 내가 발견
-(void)drawRect:(NSRect)dirtyRect
{
NSRect mOuterFrame = NSMakeRect(0, 0, 104, 94);
NSRect mSelectedFrame = NSInsetRect(mOuterFrame, 2, 2);
NSRect mRedFrame = NSInsetRect(mSelectedFrame, 2, 2);
NSRect mInnerFrame = NSInsetRect(mRedFrame, 2, 2);
[NSBezierPath setDefaultLineWidth:2.0];
[mainBackgroundColor set];
[NSBezierPath strokeRect:mOuterFrame];
if (selected)
[[NSColor yellowColor] set];
else
[mainBackgroundColor set];
[NSBezierPath strokeRect:mSelectedFrame];
if (isRedBorder)
[[NSColor redColor] set];
else
[mainBackgroundColor set];
[NSBezierPath strokeRect:mRedFrame];
[[NSColor blackColor] set];
[NSBezierPath strokeRect:mInnerFrame];
}
NSDrawRect가 아니라 NSFrameRect을 의미한다고 생각합니다. –
NSResponder - 감사합니다. 이로 인해 문제가 해결되었습니다 (dirtyRect에서 초기 외부 프레임을 기반으로하지 않음). NSFrameRect를 사용하여 좀 더 효율적으로 코드를 수정했습니다. 감사! – Hooligancat