2012-07-03 105 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

我很沮喪,我無法得到它的工作......我看到了繪製的上下文,但我不能滾動它:(。 –