问题描述
我有一个NSTextView是一个视图是NSCollectionViewItem的视图。我给用户隐藏NSTextView的选项,而是在同一个视图上调用NSView对象。
然而,当我运行NSView对象隐藏和重叠的NSTextView程序,NSTextView中的滚动不能正常工作;垂直滚动条在那里,并根据NSTextView中的内容大小相应地调整其大小。但是,实际滚动只通过突出显示NSTextView的内容并向上或向下拖动来实现。更重要的是,如果我重新创建视图没有连接到NSCollectionViewItem和NSCollectionView,它滚动很好。这是一个问题,不只是与自定义视图重叠的NSTextView,但与任何视图对象(按钮,图像井等)重叠的NSTextView,即使视图对象设置为隐藏。
为什么只有在使用NSCollectionView创建NSTextView并且有一个与之重叠的视图对象的情况下向上或向下高亮和向下拖动才能滚动?
我子类化NSTextView和覆盖mouseEntered与这:
- (void)mouseEntered:(NSEvent *)theEvent {
NSScrollView * scrollView =(NSScrollView *)self.superview.superview;
NSScroller * scroller = scrollView.verticalScroller;
[scrollView setVerticalScroller:nil];
[scrollView setVerticalScroller:scroller];
}
如果任何人对此问题发生的原因或更好的解决方案有任何想法而不只是猜测,请张贴
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?
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
这篇关于NSTextView使用NSCollectionView创建时不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!