ios - UIImage 在 UIScrollView 上缩放时 UIButton 的位置

标签 ios uiscrollview uiimageview uibutton

我有一个场景,我需要实现离线 map 概念,为此我在 UIScrollView 上使用 map 图像,在 PinchGesture 上进行缩放,效果很好。

问题

我在 map 上有一个UIButton。缩放时,按钮不会跟踪其相对于正在缩放的​​ UIImageView 的位置。我能够在不影响其大小的情况下重新构建按钮。但立场是错误的。

TLDR, 我需要在 UIScrollView 上重现带有注释有点概念的 ma​​pView ,并在其上添加 UIImage 。有人可以帮忙吗?

提前致谢:)

最佳答案

我已经找到了这个问题的答案。我最初将按钮值存储在 CGRect initialButtonFrame 中。然后我使用 ScrollView 委托(delegate)更新了按钮框架(仅是原点,而不是按钮大小的大小,因为我希望按钮不要像图像一样缩放,即;我按钮不应该缩放)

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
   [self manageImageOnScrollView];//here i managed the image's coordinates and zoom
   [self manageButtonCoordinatesWithRespectToImageWithScale:scale];
}

-(void)manageButtonCoordinatesWithRespectToImageWithScale:(float)scaleFactor
{

//initialButtonFrame is frame of button 
   self.button.frame = CGRectMake((initialButtonFrame.origin.x * scaleFactor),
                                  (initialButtonFrame.origin.y * scaleFactor),
                                           initialButtonFrame.size.width,
                                           initialButtonFrame.size.height);

   [self.scrollView addSubview:self.button];// I removed the button from superview while zooming and later added with updated button coordinates which I got here
 }

关于ios - UIImage 在 UIScrollView 上缩放时 UIButton 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16834691/

相关文章:

objective-c - Objective-C 中的 UIScrollView 中的 zoomToRect 方法不起作用

ios - 如何将 UITableView 设置为捕捉到最近的单元格?

ios - UITableViewCell 中的 Swift ScrollView 不滚动

ios - 使 UIImageView 图像稍微变小

ios - 将 UIButton 添加到 UICollectionViewCell 时的奇怪行为

ios - self 分类报告 - 是否需要美国注册公司?

ios - JSONValue 不解析 JSON 响应

iphone - 如何 "Auto SMS Sender"工作 - 在后台发送短信

iphone - nibNameOrNil 的真正含义是什么?

objective-c - 如何创建动态的UIImageView