0

I have written a code that I use for cropping purpose. The scenario is like, It has 4 uiviews

1) Top
2) Left
3) Right
4) Bottom

Each uiview is resized according to the desired change and the main uiview has a uiimageview which contains an image. when I run the code on iPhone 3, 3GS, iPad 2, iPad 4 it works fine but when i run it on iPhone 4G, it generates very undesired result. I know my code calculations are fine thats why they are working fine on every device except the iPhone 4G. What will the issue be ? Any ideas ? Is uiview calculations are different for iPhone 4 or any other reason ?

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

}

}

yunas
  • 4,143
  • 1
  • 32
  • 38
  • You need to provide some more information and some code for anybody to help you - What exactly happens on iPhone 4 that differs from the other devices? What kind of view manipulation is being done? What is the desired result? – Milk78 Mar 14 '11 at 09:55
  • Does this problem result in a visible difference? Perhaps you could post images that show the problem? – ThomasW Mar 24 '11 at 08:28
  • I'm running into a problem with dynamically resizing views that also only occurs on iPhone 4. (Actually the only other device I have on hand is an iPad.) I suspect this is a bug that only occurs with the non simulated retina display. I suspect you can still reproduce this problem even after greatly simplifying your code. – ThomasW Mar 24 '11 at 13:24
  • Hey thomas, you might be right... I will use the roundf method and will tell you accordingly that wether using the roundf method solves my problem or not... I will try to share my whole code here as well. – yunas Mar 29 '11 at 07:31

1 Answers1

1

I believe the problem you're running into is similar to a problem I'm seeing. With the retina display the touch coordinates may be non-integral, e.g. 23.5. If you use non-integral value with the frame of a view you may run into this kind of behavior. It appears that UIView doesn't support non-integral values.

Use roundf() or a similar function at some point in your calculations to avoid this problem.

ThomasW
  • 16,981
  • 4
  • 79
  • 106
  • yes this thing worked but the results were little again of the mark... what else could be the functions similar to rounf() to tackle this problem ? – yunas Mar 29 '11 at 07:58
  • There are other functions available, like floor, but that's not the point. You need to do what's appropriate for your application. Just make sure the resulting frame uses integral coordinates. – ThomasW Apr 01 '11 at 01:42