标签:
雷达使用UIScrollView做的
UIView * contanerView = [[UIView alloc] initWithFrame:self.bounds];
[self addSubview:contanerView];
_containerView = contanerView;
CGSize imageSize = imageView.contentSize; self.containerView.frame = CGRectMake(0, 0, imageSize.width, imageSize.height); imageView.bounds = CGRectMake(0, 0, imageSize.width, imageSize.height); imageView.center = CGPointMake(imageSize.width/2, imageSize.height/2);
self.contentSize = imageSize;
- (void)setMaxMinZoomScale { CGSize imageSize = self.imageView.image.size; // 图片原始尺寸 CGSize imagePresentationSize = self.imageView.contentSize; // 在当前界面中初始化显示的尺寸 CGFloat maxScale = MAX(imageSize.height / imagePresentationSize.height, imageSize.width / imagePresentationSize.width); self.maximumZoomScale = MAX(1, maxScale); self.minimumZoomScale = 1.0; }
- (void)centerContent { CGRect frame = self.containerView.frame; CGFloat top = 0, left = 0; if (self.contentSize.width < self.bounds.size.width) { left = (self.bounds.size.width - self.contentSize.width) / 2.0f; } if (self.contentSize.height < self.bounds.size.height) { top = (self.bounds.size.height - self.contentSize.height) / 2.0f; } top -= frame.origin.y; left -= frame.origin.x; _RadarScale = ((self.containerView.width)/2.f) / 30; CGFloat RadarRadiusTwo = self.containerView.width/2; self.contentInset = UIEdgeInsetsMake(top, left, top, left); for (id objc in self.subviews) { if ([objc isKindOfClass:[HeaderView class]]) { HeaderView * headerView = (HeaderView *)objc; CGFloat headerX = headerView.userModel.userX * _RadarScale; CGFloat headerY = headerView.userModel.userY * _RadarScale; headerX += RadarRadiusTwo - HeaderView_Width/2; headerY = RadarRadiusTwo - headerY - ImgScale(HeaderView_Width); headerView.frame = CGRectMake(headerX, headerY, HeaderView_Width, ImgScale(HeaderView_Width)); } } }
以上都是实现代码,现在需要有触发事件:rebackCenter
如何让所有的布局全部回到以自己为中心坐标系中(0,0),导致问题出现,首先重新认识UIScrollView中的viewForZoomingInScrollView和contentInset
标签:
原文地址:http://www.cnblogs.com/R0SS/p/4902540.html