iPhone 4G 的 uiview 调整大小和操作问题

发布于 2024-10-21 19:44:17 字数 2141 浏览 0 评论 0原文

我编写了一个用于裁剪目的的代码。场景是这样的,它有 4 个 uiviews

1) Top
2) 左
3) 右
4) 底部

每个 uiview 都会根据所需的更改调整大小,主 uiview 有一个包含图像的 uiimageview。当我在 iPhone 3、3GS、iPad 2、iPad 4 上运行代码时,它工作正常,但当我在 iPhone 4G 上运行它时,它会产生非常不想要的结果。我知道我的代码计算很好,这就是为什么它们在除 iPhone 4G 之外的所有设备上都能正常工作。 会出现什么问题呢?有什么想法吗? iPhone 4 的 uiview 计算是否不同还是有其他原因?

<代码>

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

}

}

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

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北陌 2024-10-28 19:44:17

我相信您遇到的问题与我遇到的问题类似。对于视网膜显示器,触摸坐标可能是非整数,例如 23.5。如果您在视图框架中使用非整数值,您可能会遇到这种行为。看来 UIView 不支持非整数值。

在计算中的某个时刻使用 roundf() 或类似的函数可以避免此问题。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文