我编写了一个用于裁剪目的的代码。场景就像,它有4个uiviews
1)上
2)左侧
3)右
4)底部
每个uiview根据所需的更改调整大小,主uiview具有包含图像的uiimageview。当我在iPhone 3,3GS,iPad 2,iPad 4上运行代码时它工作正常,但是当我在iPhone 4G上运行时,它会产生非常不希望的结果。我知道我的代码计算很好,这就是为什么它们在除iPhone 4G之外的每个设备上都能正常工作。 问题是什么?有任何想法吗 ? uiview计算是否与iPhone 4或其他任何原因不同?
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// messageLabel.text = @"Drag Detected";
commonCropT = leftRect.frame.origin.y; // left.y or Right.y or Top.H is same thing
commonCropB = lowerRect.frame.origin.y;// left.H or Right.H or lower.y is same thing
commonCropL = leftRect.frame.size.width; //
commonCropR = rightRect.frame.origin.x;//
commonCropH = leftRect.frame.size.height;// left.width and right.width
leftYT = leftRect.frame.origin.y;
leftH = leftRect.frame.size.height;
leftYB = leftYT + leftH;
leftW = leftRect.frame.size.width; // leftXR
rightXL = rightRect.frame.origin.x;
rightW = rightRect.frame.size.width;
rightXR = rightXL + rightW;
rightYT = rightRect.frame.origin.y;
rightH = rightRect.frame.size.height;
rightYB = rightH + rightYT;
if (isTappedOnUpperLeftCorner)
{
if (commonCropR - movedPoint.x <= kWidthDifference)
return;
if (movedPoint.y < commonCropT )
{
commonCropH = commonCropH + (commonCropT - movedPoint.y);
}
else if (movedPoint.y > commonCropT )
{
if (commonCropB - movedPoint.y <= kHeightDifference ) {
return;
}
commonCropH = commonCropH - (movedPoint.y - commonCropT);
}
commonCropL = movedPoint.x;
commonCropT = movedPoint.y;
NSLog(@" cropW = %d ",cropW);
[upperRect setFrame:CGRectMake(upperRect.frame.origin.x, upperRect.frame.origin.y, upperRect.frame.size.width, commonCropT)];
[leftRect setFrame:CGRectMake(leftRect.frame.origin.x, commonCropT, commonCropL, commonCropH)];
[rightRect setFrame:CGRectMake(commonCropR, commonCropT, rightRect.frame.size.width, commonCropH)];
}
}
commonCropT = leftRect.frame.origin.y; // left.y or Right.y or Top.H is same thing
commonCropB = lowerRect.frame.origin.y;// left.H or Right.H or lower.y is same thing
commonCropL = leftRect.frame.size.width; //
commonCropR = rightRect.frame.origin.x;//
commonCropH = leftRect.frame.size.height;// left.width and right.width
leftYT = leftRect.frame.origin.y;
leftH = leftRect.frame.size.height;
leftYB = leftYT + leftH;
leftW = leftRect.frame.size.width; // leftXR
rightXL = rightRect.frame.origin.x;
rightW = rightRect.frame.size.width;
rightXR = rightXL + rightW;
rightYT = rightRect.frame.origin.y;
rightH = rightRect.frame.size.height;
rightYB = rightH + rightYT;
if (isTappedOnUpperLeftCorner)
{
if (commonCropR - movedPoint.x <= kWidthDifference)
return;
if (movedPoint.y < commonCropT )
{
commonCropH = commonCropH + (commonCropT - movedPoint.y);
}
else if (movedPoint.y > commonCropT )
{
if (commonCropB - movedPoint.y <= kHeightDifference ) {
return;
}
commonCropH = commonCropH - (movedPoint.y - commonCropT);
}
commonCropL = movedPoint.x;
commonCropT = movedPoint.y;
NSLog(@" cropW = %d ",cropW);
[upperRect setFrame:CGRectMake(upperRect.frame.origin.x, upperRect.frame.origin.y, upperRect.frame.size.width, commonCropT)];
[leftRect setFrame:CGRectMake(leftRect.frame.origin.x, commonCropT, commonCropL, commonCropH)];
[rightRect setFrame:CGRectMake(commonCropR, commonCropT, rightRect.frame.size.width, commonCropH)];
}
答案 0 :(得分:1)
我相信你遇到的问题类似于我所看到的问题。利用视网膜显示器,触摸坐标可以是非整数的,例如, 23.5。如果对视图的框架使用非整数值,则可能会遇到此类行为。似乎UIView不支持非整数值。
在计算中的某个点使用roundf()或类似函数来避免此问题。