我有一个验证方法,通过它我可以分析特定变量是否通过了验证标准。
以下是代码:
-(void)scaleTextView:(UIPinchGestureRecognizer *)pinchGestRecognizer{
CGFloat scale = pinchGestRecognizer.scale;
CGFloat lastScale;
lastScale = 1.0;
if([pinchGestRecognizer state] == UIGestureRecognizerStateEnded) {
// Reset last scale
lastScale = 1.0;
return;
}
if ([pinchGestRecognizer state] == UIGestureRecognizerStateBegan ||
[pinchGestRecognizer state] == UIGestureRecognizerStateChanged) {
CGFloat pinchscale = [pinchGestRecognizer scale];
CGFloat scaleDiff = pinchscale - lastScale;
if (scaleDiff < 0){
scaleDiff *= 2; // speed up zoom-out
[self zoomSymbol:selectObject Scale:-scale];
}
else{
scaleDiff *= 0.7; // slow down zoom-in
[self zoomSymbol:selectObject Scale:scale];
lastScale = pinchscale;
}
}
}
我收到警告'存储到'lastScale'的值永远不会被读取'并且'存储到'scaleDiff'的值永远不会被读取' 任何人都能解释一下我的问题在这里。 谢谢大家!
答案 0 :(得分:3)
lastScale
是一个局部变量,永远不会出现在gestureRecognizer的所有状态属性中。您应该使用static
变量。
static CGFloat lastScale = 1.0;
...