2013-04-23 27 views
0

我製成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或以上的工作。我沒有線索在哪裏尋找問題,請搜索什麼......請幫忙。

+0

我已經通過將運行循環更改爲'NSRunLoopCommonModes'解決了這個問題。不知道'NSRunLoopCommonModes'和'NSDefaultRunLoopMode'有什麼區別。 – Pablo 2013-04-24 18:48:36

回答

0

可以使用CCScrollView從CCBReader庫

這裏我想補充的github倉庫 https://github.com/cocos2d/CCBReader

這個庫是關於科科斯生成器,爲cocos2d的圖形界面生成器,它的自由的讀者

Cocos2D不建議在cocos層上使用uikit,CCScrollView很容易實現,並且可以與最新版本的cocos2D和4.3以上版本一起使用。

編輯:
CCScrollLayer詢問服務呼叫 這裏GitHub的倉庫

https://github.com/cocos2d/cocos2d-iphone-extensions/tree/master/Extensions/CCScrollLayer

也許你需要修改一點點在cocos2d

的新版本類觸摸委託
+0

我使用UIScrollView的原因是爲了獲得彈跳效果和分頁。看來CCScrollView支持減速。但如何尋呼支持? – Pablo 2013-04-24 09:21:53

+0

好的,在我的情況下,我使用CCScrollLayer是一個cocos2d擴展,編輯帖子的信息 – busta117 2013-04-24 15:00:27

+0

CCScrollLayer確實支持分頁,但不支持彈跳/減速。 – Pablo 2013-04-24 18:29:17