问题描述
我正在将应用程序从 Ipad 移植到 mac.(我知道这听起来很奇怪)
I am porting an app from Ipad to mac. (I know that it sounds weird)
我坚持使用 NSScrollview.请指导我 contentsize , contentOffset 在 NSScrollview 中等效.
I stuck with NSScrollview. Please guide me contentsize , contentOffset equivalent in NSScrollview.
推荐答案
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 = N**akeSize(w,h); [nsScroll.documentView scrollPoint:N**akePoint(x,y)];
或者甚至更好:
import AppKit extension NSScrollView { var documentSize: NSSize { set { documentView?.setFrameSize(newValue) } get { documentView?.frame.size ?? NSSize.zero } } var documentOffset: NSPoint { set { documentView?.scroll(newValue) } get { documentVisibleRect.origin } } }
注意:我使用了documentSize"(和documentOffset"),因为contentSize"与 NSScrollView 的现有属性冲突.
Notes: I used 'documentSize' (and 'documentOffset') because 'contentSize' conflicts with an already existing property of NSScrollView.