2014-02-18 43 views
0

我試圖滾動的NSScrollView使用此代碼視圖的底部:滾動NSScrollView不工作

NSPoint newScrollOrigin; 
if ([[self.chatScreen documentView] isFlipped]) { 
    newScrollOrigin=NSMakePoint(0.0,NSMaxY([[self.chatScreen documentView] frame])-NSHeight([[self.chatScreen contentView] bounds])); 
} else { 
    newScrollOrigin=NSMakePoint(0.0,0.0); 
} 
self.chatScreen.backgroundColor=[NSColor redColor]; 
[[self.chatScreen documentView] scrollPoint:newScrollOrigin]; 

這些來自這裏:Apple doucmentation on scrolling

當我運行我的程序,它部分滾動到視圖的底部,屏幕顯示視圖的頂部(默認開始位置),但當我嘗試滾動時,它跳轉到頁面的底部,然後我可以正常滾動。

如果我滾動到視圖的任何部分,下一次它接收到更新(觸發它跳回到底部),看起來沒有任何事情發生,直到您嘗試滾動,這再次導致它跳回到頁面的底部。

在此先感謝。

+0

聽起來像一些滾動代碼是在不需要的時間觸發的。如果我理解正確,當您嘗試手動滾動時它會自動滾動? – Volker

+0

你從哪裏調用此代碼? – Flexicoder

+0

@Flexicoder我從一個單獨的線程調用代碼 – Alex

回答

0

您需要滾動剪輯視圖而不是文檔視圖。
文檔視圖填充了整個滾動視圖和剪輯視圖是一種疊加層,它圍繞着決定哪些部分可見。

[[self.chatScreen contentView] scrollToPoint:newScrollOrigin]; 

通知的scrollToPoint,而不是一個NSView的層支持scrollPoint 後您滾動NSClipView它總是好的做法reflectScrolledClipView從而使滾動條更新。

- (void)reflectScrolledClipView:(NSClipView *)aClipView;