我将相册实现为iOS ablum App。
现在,我想让中心点偏移。它只是喜欢下面的插图:
第一个原始图像的中心是O(x0, y0)
,放大一个的中心是O(x1, y1)
。
我想计算δx
和δy
。
我已经测试了很长时间。我可以通过CGSize
获取放大图片的scrollView.contentSize.height
。但我无法得到放大图像的中心点。
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 :(得分: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)")
答案 1 :(得分: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)
}