我正在把一个应用程序从Ipad移植到mac上。(我知道这听起来很奇怪)
我坚持使用NSScrollview。请指导我contentsize,相当于NSScrollview中的contentOffset。
发布于 2013-01-29 07:11:02
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)];
或者甚至更好:
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属性冲突。
发布于 2018-04-12 05:40:05
除了@aepryus中的几行代码外,这里还有几行更有用的代码来获取/设置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];
发布于 2011-05-06 16:31:06
文档中提供的Scroll View Programming Guide for Cocoa中列出了您需要了解的有关NSScrollView
的所有内容。
虽然看起来没有直接的等价物,但UIScrollView
的contentSize
可以比作NSScrollView
的documentView
的大小,后者是通过setDocumentView:
作为NSView
to NSScrollView
提供的可滚动内容。
可以将setContentOffset:
与NSView
的scrollPoint:
进行比较,后者使用NSPoint
来指定documentView
在NSScrollView
中的偏移量。
有关详细说明和代码示例,请参阅文档。
https://stackoverflow.com/questions/3457926
复制相似问题