我制作了UIScrollView
基于 Cocos 层的滚动机制,下面是UIScrollView
派生类的部分代码:
- (id)initWithFrame:(CGRect)scrollFrame contentFrame:(CGRect)contentFrame layer:(CCNode*)layer anchor:(int)anchor_
{
self = [super initWithFrame:scrollFrame];
if (self) {
self.contentSize = contentFrame.size;
self.delegate = self;
self.bounces = YES;
self.delaysContentTouches = NO;
self.pagingEnabled = YES;
self.scrollsToTop = NO;
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;
self.alwaysBounceHorizontal = YES;
self.alwaysBounceVertical = YES;
self.decelerationRate = UIScrollViewDecelerationRateNormal;
[self setUserInteractionEnabled:TRUE];
[self setScrollEnabled:TRUE];
self.targetLayer = layer;
anchor = anchor_;
}
return self;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGPoint dragPt = [scrollView contentOffset];
dragPt = [[CCDirector sharedDirector] convertToGL:dragPt];
dragPt.y = targetLayer.position.y;
dragPt.x = dragPt.x * -1 + anchor;
CGPoint newLayerPosition = CGPointMake(dragPt.x, dragPt.y);
[targetLayer setPosition:newLayerPosition];
}
它需要新的偏移量并移动目标层。很奇怪,我使用 4.3 作为目标 iOS 版本开始这个项目,并且图层滚动得很好。今天我尝试了 5.0/above 并且...我在调试器中看到了新的偏移量,但是图层在滚动期间根本不会改变它在屏幕上的位置。只有当页面发生变化时,我才能立即看到图层的新部分。我怀疑与 Cocos 2.0 有关。
更新:这就是我在 4.3 上所做的工作
http://www.youtube.com/watch?feature=player_embedded&v=xp6bPyAVShk
同样,这不适用于 iOS 5 或更高版本。我不知道在哪里寻找问题,搜索什么......请帮忙。