2012-02-29 7 views

答えて

2

はそれはズーム、その後、私はのサイズにオフセットコンテンツを変換することができる方法を説明するために必要フルイメージといくつかを追加します。 ///これはマップイメージのフルサイズです CGSize fullSize = CGPointMake(13900、8400);

/// determines how the current content size compares to the full size 
    float zoomFactor = size.width/self.contentSize.width; 

    /// apply the zoom factor to the content offset , this basically upscales 
    /// the content offset to apply to the dimensions of the full size map 

    float newContentOffsetX = self.contentOffset.x*zoomFactor + (self.bounds.size.width/2) *zoomFactor-300; 
    float newContentOffsetY = self.contentOffset.y*zoomFactor + (self.bounds.size.height/2) * zoomFactor-300; 

    /// not sure why i needed to subtract the 300, but the formula wasn't putting 
    /// the point in the exact center, subtracting 300 put it there in all situations though 

    CGPoint point = CGPointMake(newContentOffsetX,newContentOffsetY); 
2

自分で計算する必要があるのではないかと心配です。 contentSizeは、スクロールしたコンテンツのサイズを返します。contentOffsetは、コンテンツ内にスクロールビューの起点を与えます。その後、scrollView.bounds.sizeを使用すると、ビューの中心を見つけることができます。

はこれをテストしていませんが、多分あなたは、このようなあなたのスクロールマップにscrollView.centerを変換することができます:

CGPoint viewportCenterInMapCoords = 
     [scrollView.superview convertPoint:scrollView.center 
            toView:mapViewInsideScrollView]; 
+0

ありがとうございました - あなたの答えが私に答えをもたらしたにもかかわらず、あなたが提供したコードはうまくいかなかった。この問題はズームファクタを考慮していました。 – Brodie

関連する問題