我只是做了一个示例来检查平移手势。
平移手势正在检测并且工作正常。
但是每当我在平移手势中给出第二点时,就像CGPoint secondPoint = [sender locationOfTouch:1 inView:self.imageView];
它正在崩溃一样。
控制台正在给出消息
*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[UIPanGestureRecognizer locationOfTouch:inView:]: index (1) beyond bounds (1).'
当我使用panGestureRecognizer.maximumNumberOfTouches = 1;
panGestureRecognizer.minimumNumberOfTouches =1; 它仍然在崩溃。
当我使用时panGestureRecognizer.maximumNumberOfTouches = 2;
panGestureRecognizer.minimumNumberOfTouches = 2;
,它没有进入
- (void)panGestureHandler:(UIPanGestureRecognizer *)sender method.
谁能指导我哪里出错了。
在此先感谢。希望您的帮助。
我尝试过这种方式。
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureHandler:)];
panGestureRecognizer.maximumNumberOfTouches = 2;
[self.imageView addGestureRecognizer:panGestureRecognizer];
}
- (void)panGestureHandler:(UIPanGestureRecognizer *)sender
{
if ([sender state] == UIGestureRecognizerStateBegan )
{
CGPoint firstPoint = [sender locationOfTouch:0 inView:self.imageView];
CGPoint secondPoint = [sender locationOfTouch:1 inView:self.imageView];
}
else if ([sender state] ==UIGestureRecognizerStateEnded )
{
}
}