码迷,mamicode.com
首页 > 其他好文 > 详细

【项目】雷达界面,无法返回中心点问题

时间:2015-10-22 21:16:42      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

雷达使用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));
        }
    }
}
centerContent

以上都是实现代码,现在需要有触发事件:rebackCenter

如何让所有的布局全部回到以自己为中心坐标系中(0,0),导致问题出现,首先重新认识UIScrollView中的viewForZoomingInScrollView和contentInset

【项目】雷达界面,无法返回中心点问题

标签:

原文地址:http://www.cnblogs.com/R0SS/p/4902540.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!