2017-09-08 2 views
0

iOS ablumアプリケーションとしてアルバムを実装します。画像を拡大したときの画面の中心点の取得方法

今、私は中心点をオフセットしたいと思っていました。それだけで次の図が好き:

enter image description here

enter image description here

第原点画像の中心がO(x0, y0)であり、一の拡大の中心がO(x1, y1)あります。

そして、私はδxδyを計算したかったのです。


私は長い間テストしています。そして、私はscrollView.contentSize.heightによって画像のCGSizeを得ることができます。しかし、私は拡大画像の中心点を得ることができません。

print("\ntodo_origin_center: ", self.originCenter) 
print("todo_scale: ", scale) 
let mid = CGPoint.init(x: self.scrollView.contentSize.width, y: self.scrollView.contentSize.height) 
print("todo_mid: ", mid) 

出力:

// output 
todo_origin_center: (187.5, 250.0) 
todo_scale: 1.77122386887068 
todo_mid: (664.208950826505, 885.611934435339) 

答えて

0
let x1 = self.centerView.centerX * scale - self.scrollView.contentOffset.x 
let y1 = self.centerView.centerY * scale - self.scrollView.contentOffset.y 
let x0 = self.centerView.centerX 
let y0 = self.centerView.centerY 
print("x: \(x1)") 
print("y: \(y1)") 

print("∂x: \(x1 - x0), ∂y: \(y1 - y0)") 
print("scale: \(scale)") 
0
You can do like this 

//return the scroll view center 

func scrollViewCenter() -> CGPoint { 
    let scrollViewSize: CGSize = scrollViewVisibleSize() 
    //HERE YOU GOT CENTER POINT OF YOUR SCROLLVIEW 
    return CGPoint(x: scrollViewSize.width/2.0, y: scrollViewSize.height/2.0) 
} 

// Return scrollview size without the area overlapping with tab and nav bar. 
func scrollViewVisibleSize() -> CGSize { 
    let contentInset: UIEdgeInsets = scroll.contentInset 
    let scrollViewSize: CGSize = scroll.bounds.standardized().size 
    let width: CGFloat = scrollViewSize.width - contentInset.left - contentInset.right 
    let height: CGFloat = scrollViewSize.height - contentInset.top - contentInset.bottom 
    return CGSize(width: width, height: height) 
} 
関連する問題