我使用 Cocos2d 渲染精灵,并使用 UIGestureRecognizers 允许用户平移、旋转和缩放精灵。
我使用如下代码单独工作:
UIPinchGestureRecognizer *pinchRecognizer = [[[UIPinchGestureRecognizer alloc] initWithTarget:layer action:@selector(handlePinchFrom:)] autorelease];
[viewController.view addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[[UIRotationGestureRecognizer alloc] initWithTarget:layer action:@selector(handleRotationFrom:)] autorelease];
[viewController.view addGestureRecognizer:rotationRecognizer];
但是,如果用户在旋转时将手指捏在一起,我希望同时缩放和旋转精灵(例如,照片应用程序会执行此操作)。但不幸的是,识别器似乎陷入“旋转”或“捏合”模式,并且不会同时调用两个处理程序:(
所以,基本上,我想知道 - 这是否意味着我不能使用 UIGestureRecognizers?我可以组合两个识别器并在单个处理程序中执行所有操作吗?我是否必须将 UIGestureRecognizer 子类化为“PinchAndRotateRecognizer”之类的东西。
帮助表示赞赏:)
只需实施手势识别器:应该与手势识别器同时识别: http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer%3ashouldRecognizeSimultaneouslyWithGestureRecognizer%3a在你的代表中。
我有一个UIPinchGestureRecognizer
, a UIPanGestureRecognizer
and a UIRotationGestureRecognizer
设置完毕,我希望它们同时工作。我也有一个UITapGestureRecognizer
我做的not想要同时被认可。我所做的只是这样:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (![gestureRecognizer isKindOfClass:[UITapGestureRecognizer class]] && ![otherGestureRecognizer isKindOfClass:[UITapGestureRecognizer class]]) {
return YES;
}
return NO;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)