1
私はUIScrollView内でUIViewの変換されたCGRectを取得しようとしています。私がズームしていないとうまく動作しますが、一度ズームすると、新しいCGRectがシフトします。ここでは近い私を得ているコードは次のとおりです。ConvertRectはUIScrollViewのズームとcontentOffsetを会計処理します
CGFloat zoomScale = (scrollView.zoomScale);
CGRect newRect = [self.view convertRect:widgetView.frame fromView:scrollView];
CGPoint newPoint = [self.view convertPoint:widgetView.center fromView:scrollView];
// Increase the size of the CGRect by multiplying by the zoomScale
CGSize newSize = CGSizeMake(newRect.size.width * zoomScale, newRect.size.height * zoomScale);
// Subtract the offset of the UIScrollView for proper positioning
CGPoint newCenter = CGPointMake(newPoint.x - scrollView.contentOffset.x, newPoint.y - scrollView.contentOffset.y);
// Create rect with the proper width/height (x and y set by center)
newRect = CGRectMake(0, 0, newSize.width, newSize.height);
[self.view addSubview:widgetView];
widgetView.frame = newRect;
widgetView.center = newCenter;
私は私の問題はzoomScaleであることをかなり確信している - 私はおそらくzoomScale値に基づいて、x、y座標を変更する必要があります。私がこれまで試みてきたことはすべて成功しなかった。
私はUIScrollViewのズームのときにUIScrollViewのsubViewの座標系について非常に混乱しています。いくつかのドキュメントがこれを完全に説明していますか? – Yeung