我有一个场景,我需要实现离线 map 概念,为此我在 UIScrollView
上使用 map 图像,在 PinchGesture 上进行缩放,效果很好。
问题
我在 map 上有一个UIButton
。缩放时,按钮不会跟踪其相对于正在缩放的 UIImageView 的位置。我能够在不影响其大小的情况下重新构建按钮。但立场是错误的。
TLDR,
我需要在 UIScrollView
上重现带有注释有点概念的 mapView ,并在其上添加 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/