【问题标题】:Using convertRectToView on UIImageView in CATransform3DRotate Rotated UIView在 CATransform3DRotate 旋转的 UIView 中的 UIImageView 上使用 convertRectToView
【发布时间】:2012-06-03 17:39:00
【问题描述】:

我有一个名为 draggableImageView 的 UIImageView,它是名为 tiltedView 的 UIView 的子视图,它通过 CATransform3DRotate 向后倾斜,透视图 transform.m34 = -1 / 400.0。这样,当我拖动 draggableImageView 时,它的视角和绝对大小会发生变化,因此它似乎在 tiltedView 内的 2 空间中移动。

我想在tiltedView 中计算draggableImageView 的框架,但使用不同的坐标系(在这种情况下,一个名为viewForCoordinates 的UIView 没有倾斜并包含整个屏幕)。但是,在draggableImageView 中使用[self convertRect:self.frame toView:self.viewForCoordinates] 会输出相同大小的帧,而不管tiltedView 我的draggableImageView 位于何处。

我认为使用self.frameself.bounds 更合适,因为bounds 与superview 无关,而frame 依赖于它。但是,基于上述情况,我猜测convertRect 只是将self.frame 转换为与应用于self.frame 的超级视图的透视操作无关。

我不确定什么代码在这种情况下会有帮助,所以请告诉我我可以提供什么代码来帮助回答这个问题。

【问题讨论】:

    标签: objective-c transform frame subview bounds


    【解决方案1】:

    我解决了这个问题!

    所以我认为有两个主要问题:

    1) 当DraggableImageView 对象被触摸时,确保对象确实在- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 内通过if ([touch view] == self) 被触摸

    2) 通过self.touchLocation = [[touches anyObject] locationInView:self.superview]将触摸位置转换为superview坐标系。

    3) 将DraggableImageView 的坐标系从superview 坐标转换为viewForCoordinates 坐标系。 我认为我的错误是我从 self 而不是 superview 转换。

    4) 如果根据viewForCoordinatesDraggableImageView 的框架或位置进行更改,则计算viewForCoordinates 坐标系内的更改,然后转换回DraggableImageViewsuperview我想我忘了做这个转换:S

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多