旋转时我的程序运行良好无限制缩放或仅限制缩放而不旋转。 这是我的代码的一部分:
} else if (mode == ZOOM) {
float newDist = spacing(event);
matrix.set(savedMatrix);
if (newDist > 10f) {
float scale = newDist / oldDist;
matrix.getValues(mValues1);
float currentScale = mValues1[0];
if (currentScale * scale < MIN_ZOOM) {
scale = MIN_ZOOM / currentScale;
} else if (currentScale * scale > MAX_ZOOM) {
scale = MAX_ZOOM / currentScale;
}
matrix.postScale(scale, scale, mid.x, mid.y);
matrix.getValues(mValues1);
Log.e("ZOOM", "scale " + mValues1[0]);
}
/*
* uncomment to enable rotating
* this function conflicts with zooming limitation
*/
if (lastEvent != null) {
newRot = rotation(event);
float r = newRot - d;
matrix.postRotate(r, mid.x, mid.y);
matrix.getValues(mValues1);
Log.e("ROTATE", " scale " + mValues1[0]);
}
}
我认为在执行maxtrix.postRotate之后出现了错误,mValues1 [0] - 缩放值会被更改,并且在下一次循环中,currentScale也会被更改,因此限制缩放检查会出错。 给我一些想法。感谢任何帮助:)
答案 0 :(得分:0)
我通过其他方式修复了错误。我没有使用currentScale的矩阵值:
float currentScale = mValues1[0];
我使用其他全局变量&#34; previsousScale&#34;如下所示:
case MotionEvent.ACTION_POINTER_UP:
// second finger lifted
mode = NONE;
lastEvent = null;
previousScale *= tempScale;
if (previousScale > MAX_ZOOM)
previousScale = MAX_ZOOM;
else if (previousScale < MIN_ZOOM)
previousScale = MIN_ZOOM;
break;
以及MotionEvent.ACTION_MOVE:
} else if (mode == ZOOM) {
float newDist = spacing(event);
matrix.set(savedMatrix);
if (newDist > 10f) {
tempScale = newDist / oldDist;
if (previousScale * tempScale < MIN_ZOOM) {
tempScale = MIN_ZOOM / previousScale;
} else if (previousScale * tempScale > MAX_ZOOM) {
tempScale = MAX_ZOOM / previousScale;
}
matrix.postScale(tempScale, tempScale, mid.x, mid.y);
}
if (lastEvent != null) {
newRot = rotation(event);
float r = newRot - d;
matrix.postRotate(r, mid.x, mid.y);
}
}