【问题标题】:CGPoints and UIViewsCGPoints 和 UIViews
【发布时间】:2011-02-09 05:23:32
【问题描述】:

是否可以将 CGPoint 作为子视图放置在 UIView 内,这样当我旋转 UIView 时,CGPoint 也会随之旋转。

【问题讨论】:

    标签: iphone xcode uiview rotation cgpoint


    【解决方案1】:

    CGPoint 是一个逻辑结构,而不是图形。话虽如此,以下将产生一个围绕另一个旋转的点(称为点)。这可能不直接适用,但应该给你一些方向。关键是 CGAffineTransform。

    CGAffineTransform translateTransform = CGAffineTransformMakeTransation(point.x, point.y);
    CGAffineTransform rotateTransform = CGAffineTransformMakeRotation(angle);
    CGAffineTransform customTransform = CGAffineTransformConcat(CGAffineTransformConcat( CGAffineTransformInvert(translateTransform), rotateTransform), translateTransform);
    newPoint = CGPointApplyAffineTransform(initialPoint, customTransform);
    

    【讨论】:

      【解决方案2】:

      CGPoint(如CGSizeCGRect)是C 结构,不应该是“可绘制的”。我的意思是它们只是坐标或几何“东西”的数学表示,然后不可能将它们附加到您的显示树中。

      如果您需要在您的UIView 中显示一个“点”并且您需要对其进行控制,只需将一个子 UIView 添加到您的父 UIView 中,其框架为 1px 正方形,带有彩色背景(如果您需要显示)。在这种情况下,对父 UIView 的任何空间修改都会影响子 UIView(甚至旋转)。

      否则,如果您需要知道 CGPoint 相对于另一点旋转角度的位置,请参阅包含您需要的数学的这个不错的答案。

      Rotate a point by another point in 2D

      Ciao!

      【讨论】:

        猜你喜欢
        • 2013-02-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-06
        • 2011-01-29
        • 2012-01-10
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多