2012-02-02 16 views
12

私は実装したチャット履歴ビューでスムーズなスクロールを実装しようとしていますが、追加するコンテンツが十分大きい場合スムーススクロールは数行だけスクロールします。NSTextView、テキストを追加してスムーズにスクロールする

私の最初の推測では、ビューはまだ描画されませんでした。まだ表示されないまま描画を強制する場合でも、それはまだ破損しています。

- (void)scrollAnimated:(BOOL)animated 
{ 
    if(animated) 
    { 
     NSClipView *clipView = [[_chatHistoryView enclosingScrollView] contentView]; 

     [NSAnimationContext beginGrouping]; 
     [[NSAnimationContext currentContext] setDuration:0.100f]; 
     NSPoint constrainedPoint = [clipView constrainScrollPoint:NSMakePoint(0, CGFLOAT_MAX)]; 
     [[clipView animator] setBoundsOrigin:constrainedPoint]; 
     [NSAnimationContext endGrouping]; 
    } 
    else 
    { 
     NSRange range; 
     range.location = [[_chatHistoryView textStorage] length]; 
     range.length = 1; 
     [_chatHistoryView scrollRangeToVisible:range]; 
    } 
} 

私は間違っていますか?

+0

私はこれがあなたの問題を解決することはできません確信しているが、非アニメーションコードであなたの範囲はそれとして、範囲外となります長さ+1で終了します。 – mattmook

+0

しばらくの間、そのコードを使っていたのですが、おそらくドキュメント内で最後の文字(location + 1)がなぜ受け入れられているのか(場所+ 1)を調べなければならないでしょう。 –

答えて

2

これはあなたを助けるかもしれない...

- (void)maybeAutoscrollForThumb:(ThumbImageView *)thumb { 

autoscrollDistance = 0; 

// only autoscroll if the thumb is overlapping the thumbScrollView 
if (CGRectIntersectsRect([thumb frame], [thumbScrollView bounds])) { 

    CGPoint touchLocation = [thumb convertPoint:[thumb touchLocation] toView:thumbScrollView]; 
    float distanceFromLeftEdge = touchLocation.x - CGRectGetMinX([thumbScrollView bounds]); 
    float distanceFromRightEdge = CGRectGetMaxX([thumbScrollView bounds]) - touchLocation.x; 

    if (distanceFromLeftEdge < AUTOSCROLL_THRESHOLD) { 
     autoscrollDistance = [self autoscrollDistanceForProximityToEdge:distanceFromLeftEdge] * -1; // if scrolling left, distance is negative 
    } else if (distanceFromRightEdge < AUTOSCROLL_THRESHOLD) { 
     autoscrollDistance = [self autoscrollDistanceForProximityToEdge:distanceFromRightEdge]; 
    }   
} 

// if no autoscrolling, stop and clear timer 
if (autoscrollDistance == 0) { 
    [autoscrollTimer invalidate]; 
    autoscrollTimer = nil; 
} 

// otherwise create and start timer (if we don't already have a timer going) 
else if (autoscrollTimer == nil) { 
    autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0/60.0) 
                 target:self 
                selector:@selector(autoscrollTimerFired:) 
                userInfo:thumb 
                 repeats:YES]; 
} 

}

関連する問題