0

トリミングの目的で使用するコードを作成しました。シナリオは次のようになります。4つのuiviewがあります

1)上
2)左
3)右
4)下

各uiviewは、必要な変更に応じてサイズ変更され、メインuiviewには画像を含むuiimageviewがあります。コードをiPhone3、3GS、iPad 2、iPad 4で実行すると正常に動作しますが、iPhone 4Gで実行すると、非常に望ましくない結果が生成されます。私のコード計算は問題ないので、iPhone4Gを除くすべてのデバイスで問題なく機能しています。問題は何になりますか?何か案は ?uiviewの計算はiPhone4やその他の理由で異なりますか?

    - (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)];  

}

}

4

1 に答える 1

1

あなたが直面している問題は、私が見ている問題と似ていると思います。Retinaディスプレイでは、タッチ座標は23.5などの非整数である場合があります。ビューのフレームで非整数値を使用すると、この種の動作が発生する可能性があります。UIViewは非整数値をサポートしていないようです。

この問題を回避するには、計算のある時点でroundf()または同様の関数を使用します。

于 2011-03-28T07:56:16.177 に答える