UIButton 位置,而 UIImage 在 UIScrollView 上缩放 [英] UIButton position while UIImage zoom on UIScrollView

查看:29
本文介绍了UIButton 位置,而 UIImage 在 UIScrollView 上缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a scenario where I need to implement an Offline Map concept for which I am using the image of map on a UIScrollView that zooms on PinchGesture, which works fine.

问题

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

I have a UIButton on map. While zooming, the button does not track its position with respect to UIImageView which is being scaled.I am able to reframe the button without affecting its size. But the position is wrong.

TLDR,我需要在带有 UIImageUIScrollView 上重现带有注释的 ma​​pView .有人可以帮忙吗?

TLDR, I need to reproduce the mapView with annotation kinda concept on UIScrollView with UIImage on it. Can any one help?

提前致谢:)

推荐答案

我已经找到了答案.我最初将按钮值存储在 CGRect initialButtonFrame 中.然后我使用滚动视图委托更新了按钮框架(只有原点,而不是按钮大小的大小,因为我希望按钮不会像图像那样缩放,即我按钮不应该缩放)

I have found the answer for this. I initially stored the button value in a CGRect initialButtonFrame. Then I updated the button frame (only origins, not the size of the button size as I wanted the button not to zoom like the image ie; I button should not zoom) using the 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
 }

这篇关于UIButton 位置,而 UIImage 在 UIScrollView 上缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆