当调用方法updateTopViewHorizontalCenterWithRecognizer时,我无法找到我的应用崩溃的原因。
知道如何解决导致应用崩溃的错误吗?
错误记录
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x0000000d
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x39400626 objc_msgSend + 5
1 UIKit 0x3152000d _UIGestureRecognizerSendActions + 196
2 UIKit 0x313cb503 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1138
3 UIKit 0x31772af5 ___UIGestureRecognizerUpdate_block_invoke + 48
4 UIKit 0x31392373 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 218
5 UIKit 0x31390abb _UIGestureRecognizerUpdate + 282
6 CoreFoundation 0x2eb492a5 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x2eb46c49 __CFRunLoopDoObservers + 284
8 CoreFoundation 0x2eb46f8b __CFRunLoopRun + 730
9 CoreFoundation 0x2eab1f0f CFRunLoopRunSpecific + 522
10 CoreFoundation 0x2eab1cf3 CFRunLoopRunInMode + 106
11 GraphicsServices 0x33a0a663 GSEventRunModal + 138
12 UIKit 0x313fd16d UIApplicationMain + 1136
代码,当用户从左向右滑动时,调用此方法以显示左侧的菜单
- (void)updateTopViewHorizontalCenterWithRecognizer:(UIPanGestureRecognizer *)recognizer
{
//trying to avoid a error
if( recognizer == nil ) return;
CGPoint currentTouchPoint = [recognizer locationInView:self.view];
CGFloat currentTouchPositionX = currentTouchPoint.x;
if (recognizer.state == UIGestureRecognizerStateBegan) {
self.initialTouchPositionX = currentTouchPositionX;
self.initialHoizontalCenter = self.topView.center.x;
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:self.view];
if(fabs(translation.x) > fabs(translation.y))
{
CGFloat panAmount = self.initialTouchPositionX - currentTouchPositionX;
CGFloat newCenterPosition = self.initialHoizontalCenter - panAmount;
...
[self topViewHorizontalCenterWillChange:newCenterPosition];
[self updateTopViewHorizontalCenter:newCenterPosition];
[self topViewHorizontalCenterDidChange:newCenterPosition];
}
} else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
CGPoint currentVelocityPoint = [recognizer velocityInView:self.view];
CGFloat currentVelocityX = currentVelocityPoint.x;
if ([self underLeftShowing] && currentVelocityX > 100) {
[self anchorTopViewTo:ECRight];
} else if ([self underRightShowing] && currentVelocityX < 100) {
[self anchorTopViewTo:ECLeft];
} else {
[self resetTopView];
}
}
}