【问题标题】:Making a position indicator 'map' of position in a scrollview iOS在滚动视图iOS中制作位置指示器“地图”
【发布时间】:2012-07-20 10:11:00
【问题描述】:

我有一个包含大图像大小的滚动视图的视图,我想为您在滚动视图中的位置添加一个位置指示器,就像游戏中的地图一样。

我在滚动视图的顶部创建了一个较小版本的图像,我想知道如何在我的较小版本中添加一个相对于滚动视图缩放比例的大小和位置的矩形查看,以在小图像上指示您当前正在查看的大图像的哪一部分?我的目标是使用 ARC 的 iOS 5+。

这是我到目前为止所拥有的 - 它似乎正确设置了原点,但是当我放大它时它会变小,反之亦然:

int scrollxint = self.scrollView.bounds.origin.x;
int scrollyint = self.scrollView.bounds.origin.y;
int scrollxlength = self.scrollView.contentSize.width;
int scrollylength = self.scrollView.contentSize.height;

int reducedscrollxint = (scrollxint*0.05);
int reducedscrollyint = (scrollyint*0.05);
int reducedscrollxlength = (scrollxlength*0.05);
int reducedscrollylength = (scrollylength*0.05);

areaFrame.frame = CGRectMake(reducedscrollxint, reducedscrollyint, reducedscrollxlength, reducedscrollylength);
[self.mapView addSubview:areaFrame];

任何帮助将不胜感激。

【问题讨论】:

    标签: ios uiscrollview position


    【解决方案1】:

    我必须使用相对于区域指示器原始大小的缩放比例来完成这项工作,但这段代码对我有用:

    int scrollxint = self.scrollView.bounds.origin.x;
    int scrollyint = self.scrollView.bounds.origin.y;
    
    float scale = self.scrollView.zoomScale;
    
    int reducedscrollxint = (scrollxint*0.05);
    int reducedscrollyint = (scrollyint*0.05);
    
    
    areaFrame.frame = CGRectMake(reducedscrollxint, reducedscrollyint, (10/scale), (6.5/scale));
    [self.mapView addSubview:areaFrame];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 2015-01-21
      • 1970-01-01
      • 1970-01-01
      • 2014-05-01
      • 2013-12-27
      • 1970-01-01
      相关资源
      最近更新 更多