在Xcode/iPhone模拟器中工作,我有一个应用程序UIGestureRecognizers
在其中用于捏,Tap和Pan。如果不更改任何代码,就不再识别捏合(我在移动鼠标以显示两个灰色圆圈或分开的同时按住选项键)。潘和龙头仍然可以工作。还有其他人遇到这个问题吗?
看来,识别器本身或模拟器出现了问题,因为以下用于捏合的代码从未被调用,但它适用于Panning。
- (void)pinch:(UIPinchGestureRecognizer *)gesture
{
NSLog(@"in pinch method");
if ((gesture.state == UIGestureRecognizerStateChanged) ||
(gesture.state == UIGestureRecognizerStateEnded)) {
self.scale *= gesture.scale; // adjust our scale
gesture.scale = 1; // reset gestures scale so future changes are incremental
}
}
- (void)tap:(UITapGestureRecognizer *)gesture
{
NSLog(@"in tap method");
if (gesture.state == UIGestureRecognizerStateEnded)
self.originInPixels = [gesture locationInView:self];
}
我尝试使用一个简单的MKMAPVIEW创建一个新应用,该应用程序正确加载了地图,然后Pan和tap Work -pinch仍然不起作用。
我正在iOS 5.1工作。
有什么想法?
请尝试此
将此代码包括到您的项目
示例.h
CGFloat lastScale;
CGPoint lastPoint;
示例.m
- (void)ViewDidload{
UIPinchGestureRecognizer *pinchGesture = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinch:)];
[self addGestureRecognizer:pinchGesture];
[pinchGesture release];
}
- (void)handingpinch :( uipinchgestureRerecognizer *)gesturerecognizer {
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = [gestureRecognizer scale];
}
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
[gestureRecognizer state] == UIGestureRecognizerStateChanged) {
CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];
NSLog(@"%f",currentScale);
// Constants to adjust the max/min values of zoom
const CGFloat kMaxScale = 3.0;
const CGFloat kMinScale = 1.0;
CGFloat newScale = 1 - (lastScale - [gestureRecognizer scale]);
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
NSLog(@"%f",lastScale);
[gestureRecognizer view].transform = transform;
lastScale = [gestureRecognizer scale];
}
}
UIGestureRecognizer
再次自行工作,我仍然不确定为什么。它可能很简单,因为我没有按下鼠标按钮,同时还要按住选项键,但是我以前尝试过。
感谢上述建议。
我在MacBook Air Trackpad上使用Xcode 4.5.2遇到了相同的问题,以为[option] [单手指触摸运动]会捏住(灰色球进出)。
但是,您需要应用[选项] [3手指触摸]才能工作。
这在模拟器中起作用,但是在连接的iOS设备上运行时,烦人没有帮助。尽管我下载的应用程序有效,但是连接到Xcode的iPhone运行,AGH!