转换后获取帧值的最佳方法是什么?

时间:2011-10-30 04:41:50

标签: iphone ios cocoa-touch core-graphics

我有一个附有pinchgesturerecognizer的imageview。在pinchgesturerecognizer委托方法中,我需要在变换发生之前计算变换的帧值,以便查看缩放是否已将imageview推出窗口的边界。我知道我需要使用CGRectApplyAffineTransform每次计算帧值,但由于在第一次转换执行后imageview帧值无效,我是否需要将更新帧值存储在实例变量中并每次都保持更新发生转换,或者有什么方法我可以从imageview本身获得这个值?

1 个答案:

答案 0 :(得分:1)

所以你想检查UIImageView是否在其窗口内?

我认为您可以忽略视图框,而是开始计算 从视角来看。这将包括您应用于视图的转换。

Apple在 View for iOS编程指南中有一个名为框架,边界和中心属性的关系的部分。

CGRect imageViewBounds = imageView.bounds;
CGRect imageViewBoundsInWindow = [imageView convertRect:imageViewBounds
                                                 toView:nil];
CGRect windowBounds = imageView.window.bounds;
if ( CGRectIntersectsRect( windowBounds, imageViewBoundsInWindow ) ) {
     // imageView is visible in its window
}
相关问题