【问题标题】:Best way to obtain frame value after transform?转换后获取帧值的最佳方法?
【发布时间】:2011-10-30 04:41:50
【问题描述】:
我有一个附加了 pinchgesturerecognizer 的 imageview。在 pinchgesturerecognizer 委托方法中,我需要在转换发生之前计算转换的帧值,以便查看缩放是否将 imageview 推到了窗口的边界之外。我知道我每次都需要使用 CGRectApplyAffineTransform 来计算帧值,但是由于执行第一次转换后 imageview 帧值将无效,我现在是否需要将更新帧值存储在实例变量中并每次都更新它发生转换,或者有什么方法可以从图像视图本身获得这个值?
【问题讨论】:
标签:
iphone
ios
cocoa-touch
core-graphics
【解决方案1】:
所以您想检查UIImageView 是否在其窗口内?
我认为您可以忽略视图框架而开始计算
从视图边界。这将包括您已应用于视图的转换。
Apple 在 View Programming Guide for iOS 中有一个名为 Frame、Bounds 和 Center 属性的关系 的部分。
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
}