仿苹果系统相机缩放控件封装

no图说个jb。先上图:


zoom_pre.gif

demo路径 https://github.com/DawnzrXie/AppleZoomView

1.圆心不动先创建好控件(背景大圆,小点所在的圆)

- (void)configurationUI {
    
    //加转动手势
    UIPanGestureRecognizer *pgr =[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(zhuanPgr:)];
    [self addGestureRecognizer:pgr];
    
    self.layer.masksToBounds = YES;
    self.bigRoundView = [[UIView alloc] init];
    self.bigRoundView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
    [self addSubview:self.bigRoundView];
    
    self.smallRoundBGView = [[UIView alloc] init];
    [self addSubview:self.smallRoundBGView];
    
    [self.bigRoundView addSubview:self.multipleLabel];
    
    for (int i=0; i

2.刷新UI

#pragma mark -- 刷新UI
- (void)refreshUI
{
    
    //大圆
    self.bigRoundView.frame = CGRectMake(0, 0, 2*self.radius, 2*self.radius);
    self.bigRoundView.center = self.roundCenterPoint;
    self.bigRoundView.layer.cornerRadius = self.radius;
    self.bigRoundView.layer.masksToBounds = YES;
    self.bigRoundView.layer.borderWidth = 1;
    self.bigRoundView.layer.borderColor = [UIColor colorWithWhite:1 alpha:0.2].CGColor;
    
    //小圆点背景
    self.smallRoundBGView.frame = CGRectMake(0, 0, 2*self.radius, 2*self.radius);
    self.smallRoundBGView.center = self.roundCenterPoint;
    
    
    //显示倍数的label
    self.multipleLabel.center = CGPointMake(self.radius, self.margin);
    
    self.pointArray = [self creatPointArrayWithPoint:self.roundCenterPoint r:self.radius-self.margin];
    
    for (int i=0; i

3.出现动画和消失动画

//开始动画
- (void)startZoomScaleViewWithScaleNum:(NSInteger)scaleNum {
    self.startAngle = self.subViewAngle-(scaleNum-1)*self.subViewAngle/6;
    self.pointArray = [self creatPointArrayWithPoint:self.roundCenterPoint r:self.radius-self.margin];
    for (int i=0; i

4.手势转动动画

#pragma mark - 转动手势
-(void)zhuanPgr:(UIPanGestureRecognizer *)pgr
{
    
    if(pgr.state==UIGestureRecognizerStateBegan){
        
        self.beginPoint=[pgr locationInView:self];
        self.isBeginTouch = YES;
        if (self.isPanBlock) {
            self.isPanBlock(YES);
        }
    }else if (pgr.state==UIGestureRecognizerStateChanged){
        self.movePoint= [pgr locationInView:self];
        
        [self scrollowRadius];
    }else if (pgr.state==UIGestureRecognizerStateEnded){
        
        if (self.isPanBlock) {
            self.isPanBlock(NO);
        }
        [self scrollowRadius];
    }
}

#pragma mark -- 移动小点
- (void)scrollowRadius {
    
    CGFloat beginAngle = 0;
    if (self.beginPoint.x  M_PI_2) {
        self.startAngle = M_PI_2;
    }
    NSLog(@"self.startAngle = %f",self.startAngle);
    self.pointArray = [self creatPointArrayWithPoint:self.roundCenterPoint r:self.radius-self.margin];
    for (int i=0; i

5.使用方法

CGFloat bottomView_h = ([ViewController safeAreaInset].top > 0 ? 100 : 80);
    __weak typeof(self) weakSelf = self;
    //缩放控件
    self.zoomView = [[DawnXZRzoomView alloc] initWithBottom:bottomView_h margin:30 number:28];
    [self.view addSubview:self.zoomView];
    self.zoomView.isPanBlock = ^(BOOL isPan) {
        if (isPan) { //在缩放视图上
            [NSObject cancelPreviousPerformRequestsWithTarget:weakSelf selector:@selector(zoomViewHidden) object:nil];
        } else {
            [weakSelf performSelector:@selector(zoomViewHidden) withObject:nil afterDelay:2];
            
        }
    };
    self.zoomView.currentZoom = ^(NSInteger currentScale) {
        [weakSelf scaleBtnStatus:currentScale];
    };

详情见demo https://github.com/DawnzrXie/AppleZoomView

你可能感兴趣的:(仿苹果系统相机缩放控件封装)