【问题标题】:Why rotating imageView, it changes position?为什么旋转 imageView,它会改变位置?
【发布时间】:2012-12-09 11:15:34
【问题描述】:

当我使用时: ImageView.transform = CGAffineTransformRotate(ImageView.transform, rotation);每次我旋转 imageView 和 NSLog(@"x:%f y:%f", ImageView.frame.orgin.x, ImageView.frame.orgin.y),x 和 y 总是改变值??为什么?

【问题讨论】:

    标签: iphone uiimageview frame nslog


    【解决方案1】:

    .frame.origin 是你的左上角UIImageView,因为你在旋转它,所以左上角在移动。如果您访问.center,它应该保持不变。

    【讨论】:

    • 当我移动视图时使用: CGAffineTransformTranslate(view.transform, difx, dify);我得到:view.center.x,当我移动它时这个值不会改变??
    • @HuỳnhPhong 中心会在您移动视图时发生变化。通过设置平移变换,您只是显示偏移到视图位置的内容。翻译移动视图。
    • 谢谢!使用 CGAffineTransformTranslate 移动视图时如何获取当前中心点?
    • 获取翻译:view.transform.txview.transform.ty。这些坐标是相对于视图的center,所以要获得绝对X:view.center.x + view.transform.tx
    【解决方案2】:

    UIView documentation 声明

    警告:如果此属性不是恒等变换,则 frame 属性的值未定义,因此应被忽略。

    关于 UIView 的转换属性。由于您正在分配转换,因此很可能不再是身份转换,因此帧值未定义,应该被忽略。

    【讨论】:

    • 这很奇怪,因为对我来说frame 总是作为旋转视图的边界框。
    • 我同意这听起来很奇怪,而且我还使用了 frame 属性作为“superview 看到它的方式”,然后 bounds 给出了实际的旋转视图坐标。我今天第一次看到这个文档。
    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-24
    相关资源
    最近更新 更多