我製成UIScrollView
基於科科斯層滾動機制,這裏是從UIScrollView
派生類的代碼的一部分:層定位工作只爲4.3目標
- (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 /以上版本...我在調試器中看到新的偏移量,但是在滾動過程中,圖層並沒有改變它在屏幕上的位置。只有當頁面發生變化時,我才能立即看到圖層的新部分。我懷疑與Cocos 2.0有關。
更新: 這就是我工作的4.3
http://www.youtube.com/watch?feature=player_embedded&v=xp6bPyAVShk
再次,這並不在iOS 5或以上的工作。我沒有線索在哪裏尋找問題,請搜索什麼......請幫忙。
我已經通過將運行循環更改爲'NSRunLoopCommonModes'解決了這個問題。不知道'NSRunLoopCommonModes'和'NSDefaultRunLoopMode'有什麼區別。 – Pablo 2013-04-24 18:48:36