开发者

Use NSScrollView together with Cocos2d-mac (NSOpenGLView)

开发者 https://www.devze.com 2023-03-10 01:05 出处:网络
Has anybody used a NSScrollView to control scrolling using the cocos2d-mac framework? After much struggling I managed to make U开发者_Python百科IScrollView work with cocos2d-ios. Any pointers to usin

Has anybody used a NSScrollView to control scrolling using the cocos2d-mac framework?

After much struggling I managed to make U开发者_Python百科IScrollView work with cocos2d-ios. Any pointers to using NSScrollView together with a NSOpenGLView would be appreciated.


I finally managed to get a NSScrollView working within my cocos2d-mac Xib.

The trick is that you have to programmatically overlay the OpenGLView over the NSScrollView main view (leaving room for the scroll bars) by first setting up a fake view as the scrollView's documentView, and then removing the openGLView from its parent view and adding it again (so the OpenGLView is drawn over the ScrollView). You can do it as follows:

appDelegate = [[NSApplication sharedApplication] delegate];
// Set up NSScrollView with dummy empty view as big as the layer
NSRect rect = NSMakeRect(0, 0, myLayer.width, myLayer.height);
NSView *view = [[NSView alloc] initWithFrame:rect]; 
appDelegate.scrollView.documentView = view;
[view release];

// Push OpenGLView back to front 
[appDelegate.glView removeFromSuperview];  
[appDelegate.splitLeftView addSubview:appDelegate.glView];

And then, you should use the scroll bars events to update the myLayer position accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消