2012-07-03 86 views
1

我正在将使用此tutorial的iPhone应用程序移植到Mac应用程序中。我已经能够在NSScrollView中显示文本,但我无法滚动文本,我希望有人知道我错过了什么。NSScrollView不滚动

在iPhone应用程序,CTView从UIScrollView的

CTView.h子类:

@interface CTView : UIScrollView <UIScrollViewDelegate> { 

1)但是没有NSScrollViewDelegate在了AppKit。缺少委托接口到NSScrollView的问题?

所以对于Mac应用程序,CTView.h如下所示:

@interface CTView : NSScrollView 

在CTView.m我

[self setHasHorizontalScroller:YES]; 
[self setAcceptsTouchEvents:YES]; 

也在里面CTView.m创建帧的NSMutableArray的作为

self.frames = [NSMutableArray array]; 

并用阵列填充阵列。我还设置了完整的大图文档视图,我希望能够通过为滚动框架:

[[self contentView] setFrame:[self bounds]]; 
[self.documentView setFrame: NSMakeRect(0, 0, totalPages * self.bounds.size.width, textFrame.size.height)]; 

第一帧是在CTView可见的,但是当我移动水平滚动条,第二帧不会显示在CTView中。

我使用Xcode 4.3.3和Mac OS X 10.7.4。

有谁知道我需要做什么不同于UIScrollView的NSScrollView能够滚动浏览框架?

回答

1

终于搞明白了。呼!

1)NSScrollView需要其documentView的视图,其中documentView是滚动的内容。因此,在笔尖我创建包含用于documentView一个视图和documentView设置为视图NSScrollView如CTView.m

NSArray *viewArray  = [self subviews]; 
NSArray *docViewArray = [[viewArray objectAtIndex:0] subviews]; 
NSView *docView  = [docViewArray objectAtIndex:0]; 

[self setDocumentView:docView]; 

2所示的代码)然后,我添加的帧的数组,即会通常会添加到UIScrollView到NSScrollView的documentView。该帧数组由多个内容元素组成。

while (textPos < [attString length]) { 
    CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(textPos, 0), innerPath, NULL); 
    CFRange frameRange = CTFrameGetVisibleStringRange(frame); 

    CTColumnView* content = [[[CTColumnView alloc] initWithFrame: NSMakeRect(0, 0, self.contentSize.width, self.contentSize.height)] autorelease]; 
    [docView addSubview: content]; // <<-- Here is where the frames are added to the documentView 
    textPos += frameRange.length; 
    } 

而且做到了这一点。

+1

就像未来的小窍门一样,您应该避免使用与Apple框架相同的双字母前缀! – JustSid

+0

我很沮丧,我无法得到它的工作......我看到了绘制的上下文,但我不能滚动它:(。 –