NSTextView does not scroll when created with NSCollectionView

旧时模样 提交于 2019-12-08 03:30:28

问题


I have an NSTextView that is on a view that is the view of an NSCollectionViewItem. I give the user the option to hide the NSTextView and instead bring up an NSView object in its place on the same view.

However, when I run the program with the NSView object hidden and overlapping the NSTextView, scrolling in the NSTextView does not work correctly; The vertical scroll bar is there and adjusts its size accordingly to the size of the content in the NSTextView. However, the actual scrolling only works by highlighting the NSTextView's content and dragging upwards or downwards. What's more is that if I recreate the view without it being connected to an NSCollectionViewItem and NSCollectionView, it scrolls fine. This is an issue that happens not just with the custom view I have overlapping the NSTextView, but with any view object (buttons, image wells, etc) that overlaps an NSTextView, even if the view object is set as hidden.

Why is scrolling only possible when highlighting and dragging upwards or downwards if the NSTextView is being created with NSCollectionView and there is a view object overlapping it?


回答1:


Well, I have found a solution that makes little sense but seems to work fine. I subclassed NSTextView and overrode mouseEntered with this:

-(void) mouseEntered:(NSEvent *)theEvent {

    NSScrollView *scrollView=(NSScrollView*)self.superview.superview;
    NSScroller *scroller=scrollView.verticalScroller;
    [scrollView setVerticalScroller:nil];
    [scrollView setVerticalScroller:scroller];
}

If anyone has any idea as to why this issue is happening or a better solution and not just a guess-around, please post it



来源:https://stackoverflow.com/questions/22335956/nstextview-does-not-scroll-when-created-with-nscollectionview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!