contentsize and contentOffset equivalent in NSScroll view

爱⌒轻易说出口 提交于 2019-12-17 22:34:18

问题


I am porting an app from Ipad to mac. (I know that it sounds weird)

I stuck with NSScrollview. Please guide me contentsize , contentOffset equivalent in NSScrollview.


回答1:


UIScrollView* uiScroll;
uiScroll.contentSize;
uiScroll.contentOffset;
uiScroll.contentSize = CGSizeMake(w,h);
uiScroll.contentOffset = CGPointMake(x,y);

=

NSScrollView* nsScroll;
nsScroll.documentView.frame.size;
nsScroll.documentVisibleRect.origin;
nsScroll.documentView.frameSize = NSMakeSize(w,h);
[nsScroll.documentView scrollPoint:NSMakePoint(x,y)];

Edit: modernized the syntax




回答2:


In addition to the lines from @aepryus, here are a couple more useful lines for getting/setting the scroll offset on macOS:

//Get the current scroll offset:
_contentViewOffset = scrollView.contentView.bounds.origin;

//Set the scroll offset from the retrieved point:
NSPoint scrollPoint = [scrollView.contentView convertPoint:_contentViewOffset toView:scrollView.documentView];
[scrollView.documentView scrollPoint:scrollPoint];



回答3:


Everything you need to know about NSScrollView is laid out in the Scroll View Programming Guide for Cocoa provided in the documentation.

Although it doesn't appear that there's a direct equivalent, UIScrollView's contentSize can be likened to the size of NSScrollView's documentView, which is the scrollable content provided as an NSView to NSScrollView with setDocumentView:.

setContentOffset: can be compared to NSView's scrollPoint:, which uses an NSPoint to specify the offset of the documentView within the NSScrollView.

See the documentation for elaboration and code examples.



来源:https://stackoverflow.com/questions/3457926/contentsize-and-contentoffset-equivalent-in-nsscroll-view

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