• hibou 主界面自己侧滑的定义


    要打滑View参加UIPanGestureRecognizer


    #pragma mark 手势识别器回调方法

    - (void)dragView:(UIPanGestureRecognizer *)gesture{

        switch (gesture.state) {

            case UIGestureRecognizerStateBegan:

                [self startDrag];

                break;

                

            case UIGestureRecognizerStateEnded:

                [self endDrag];

                break;

            default:

                [self Draging:gesture];

                break;

        }

    }


    #pragma mark 開始拖动,记录下開始的x

    - (void)startDrag{

        CGRect frame = _mainView.frame;

        _lastDownX = frame.origin.x;

    }


    #pragma mark 正在拖动,View跟着动

    - (void)Draging:(UIPanGestureRecognizer *)gesture{

        CGFloat maxX = [UIScreen mainScreen].bounds.size.width * kSlideRatio;

        CGPoint transform = [gesture translationInView:_mainView];

        

        CGRect frame = _mainView.frame;

        frame.origin.x = _lastDownX + transform.x;

        

        if (frame.origin.x < 0) {   //不能够移动到屏幕左边去

            frame.origin.x = 0;

        }else if(frame.origin.x > maxX){

            frame.origin.x = maxX;  //限制移动的最右边

        }

        _mainView.frame = frame;

        

        // 设置界面scale动画

        CGFloat tx = frame.origin.x;

        if (tx < 0) {

            tx = 0;

        }

        CGFloat txScale = tx / _settingsViewController.view.frame.size.width;

        // imageview缩放

        double scale = kDefaultSettingScale + txScale * (1 - kDefaultSettingScale);

        if (scale > 1){

            scale = 1;

        }

        

        CGAffineTransform cgTransform = CGAffineTransformMakeScale(scale, scale);

        [_settingsViewController setAnimationScale:cgTransform];

    }


    #pragma mark 拖动结束,推断要往哪边滚动

    - (void)endDrag{

        int maxX = [self getSettingRight];

        int currentX = _mainView.frame.origin.x;

        if (currentX < maxX * 0.5) {    //没到一半,回到左边

            currentX = 0;

        }else{      //回到右边

            currentX = maxX;

        }

        

        CGRect frame = _mainView.frame;

        frame.origin.x = currentX;

        [self scrollMainViewToFrame:frame withDuration:0.25];

    }


    版权声明:本文博主原创文章,博客,未经同意不得转载。

  • 相关阅读:
    hdu-1698(线段树,区间修改)
    hdu-1394(线段树)
    hdu-1166(线段树)
    hdu-1251(string+map)
    hdu-1711(kmp算法)
    hdu-2191(完全背包+二进制优化模板)
    hdu-2844(完全背包+二进制优化模板)
    hdu-1171(多重背包+二进制优化)
    SpringMVC 参数中接收数组、List写法
    如何高效的查询数组中是否包含某个值
  • 原文地址:https://www.cnblogs.com/hrhguanli/p/4835348.html
Copyright © 2020-2023  润新知