1

我有一个 cocos2d CCLayer 类,它既有 CCSprites 又有 UIButtons。我希望玩家能够在屏幕上触摸和拖动 UIButtons,当手指松开时,我想执行一些操作。

这是我创建 UIButton 并添加到图层的代码片段 -

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(240, 200, 50, 50)];

[[[[CCDirector sharedDirector] openGLView] window] addSubview:button]; 

[button addTarget:self action:@selector(buttonMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];

我可以在 cocos2d 层内移动 UIButton。我的问题是,我怎样才能知道手指何时从 UIButton 释放?

PS/我阅读了 Ray Wenderlich 在 cocos2d 中关于 UIView 的教程以及 Steffen Itterheim 的 Learn Cocos2d 游戏开发,但它们都没有涵盖如何管理对 CCLayer 内的 UIKit 元素的触摸,或者我认为。

4

1 回答 1

0

您是否尝试过使用UIControlEventTouchUpInside/UIControlEventTouchUpOutside控制事件?

于 2012-10-22T11:08:35.943 回答