2012-02-02 18 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

थोड़ी देर के लिए उस कोड का उपयोग कर रहे थे, मुझे शायद दस्तावेज़ों में देखना होगा कि आखिरी चार के (स्थान + 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]; 
} 

}

संबंधित मुद्दे