zoukankan      html  css  js  c++  java
  • 抽屉效果

    #import "DragerViewController.h"

     

    @interface DragerViewController ()

     

    @property (nonatomic, weakUIView *leftV;

    @property (nonatomic, weakUIView *rightV;

    @property (nonatomic, weakUIView *mainV;

     

    @end

     

    @implementation DragerViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

     

        //添加子控件

        [self setUp];

        

        

        //添加手势

        UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];

        

        [self.mainV addGestureRecognizer:pan];

    }

     

    - (void)pan:(UIPanGestureRecognizer *)pan{

        

        //获取偏移量

        CGPoint transP = [pan  translationInView:self.mainV];

        //为什么不使用transform,是因为我们还要去修改高度,使用transform,只能修改,x,y

        //self.mainV.transform = CGAffineTransformTranslate(self.mainV.transform, transP.x, 0);

     

        self.mainV.frame = [self frameWithOffsetX:transP.x];

        //判断拖动的方向

        if(self.mainV.frame.origin.x > 0){

            //向右

            self.rightV.hidden = YES;

        }else if(self.mainV.frame.origin.x < 0){

            //向左

            self.rightV.hidden = NO;

        }

     

        //复位

        [pan setTranslation:CGPointZero inView:self.mainV];

        

    }

     

    //根据偏移量计算MainVframe

    - (CGRect)frameWithOffsetX:(CGFloat)offsetX {

        CGRect frame = self.mainV.frame;

        frame.origin.x += offsetX;

     

        return frame;

    }

     

     

     

     

    - (void)setUp{

        

        //leftV

        UIView *leftV = [[UIView alloc] initWithFrame:self.view.bounds];

        leftV.backgroundColor = [UIColor blueColor];

        self.leftV = leftV;

        [self.view addSubview:leftV];

        //rightV

        UIView *rightV = [[UIView alloc] initWithFrame:self.view.bounds];

        rightV.backgroundColor = [UIColor greenColor];

        self.rightV = rightV;

        [self.view addSubview:rightV];

        //mianV

        UIView *mainV = [[UIView alloc] initWithFrame:self.view.bounds];

        mainV.backgroundColor = [UIColor redColor];

        self.mainV = mainV;

        [self.view addSubview:mainV];

    }

     

     

     

     

    @end

  • 相关阅读:
    git 常用命令
    spring源码-事件&监听3.6
    spring源码-国际化-3.5
    spring源码-Aware-3.4
    spring源码-BeanPostProcessor-3.3
    springboot中对yaml文件的解析
    数组Array.sort()排序的方法
    【转】js 对象按照键值(不分区大小写)排序,生成签名方法
    【转】JS常用函数整合库 lutils
    VS2017调试出现异常浏览器直接关闭的解决办法
  • 原文地址:https://www.cnblogs.com/liuzhenjie/p/5455703.html
Copyright © 2011-2022 走看看