好的,老实说,我会将窗口框架放在比滚动对象更高的 z 位置......如果你不这样做,你可能不得不为窗口内容动态裁剪和更改精灵,讨厌(至少这是我可以的一种方式这样做,无需进一步研究)。
所以 :
// initialize this logic somewhere useful
CCNode scrollableContent;
CCSprite windowFrame;
BOOL isScrollPossible;
[self addChild:scrollableContent z:0];
[self addChild:windowFrame z:1];
// and in the touch delegate methods
-(void) ccTouchBegan:{
check if the touch happened in the window, if yes, scrolling is possible
}
-(void) ccTouchMoved:{
if (isScrollPossible) {
compute displacement
compute nextPosition for scrollableContent node;
if ( nextPosition in window ) {
// make scrollableContent follow touch
scrollableContent.position=nextPosition;
} else {
// stop any further scrolling until the next 'touch began'
isScrollPossible=NO;
}
} else {
// scroll not possible, do nothing
}
}
这是基本思想。您可能需要钳位逻辑来防止可滚动内容爬出窗口边缘。
编辑错别字。