如何确定滚动视图中当前可见的区域并确定中心? [英] How can I determine the area currently visible in a scrollview and determine the center?
本文介绍了如何确定滚动视图中当前可见的区域并确定中心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个地图应用程序,用户可以在其中手动放置航点.我希望他们按下航点按钮,并将航点放置在内容视图上当前可见视图的中心.
I have a map app where the user can place waypoints manually. I would like for them to press the waypoint button and have a waypoint placed in the center of their currently visible view on the content view.
推荐答案
需要考虑缩放的程度,然后可以将内容偏移量转换为完整图像的大小并添加一些内容.///这是地图图像的完整大小CGSize fullSize = CGPointMake(13900,8400);
Need to account for how zoomed it is, then I can convert the content offset to the size of the full image and add some. /// this is the full size of the map image 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 );
这篇关于如何确定滚动视图中当前可见的区域并确定中心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文