斜对角抽屉式效果原理

斜对角抽屉效果

一、移动

第一步:

1.创建左、中、右三个view

2.self.view addsubview:左、中、右

第二步:

1、touchMove触摸响应:获取当前触摸点

2、拿到移动前的点[touch previousLocationInView:self.view];

3、获取两点之间的距离

4、设置mainview的frame:

1)CGRect frame=mainview.frame

2)frame.origin.x+=offsetx(offsetx是3点求出来的距离)

3)mainview.frame=frame
第三步:

KVO监听main view的frame[mainview addobject。。。forkeypath:@“frame” options:。。。new constext];

observeValueForKeyPath:。。。{数据在change字典里

if(mainview.origin.x < 0){//往左移动

    右边view.hidden=NO;

    左边view.hidden=YES;

  }
}

第四步:

在touchMove里掉用方法getCurrentFrameWithOffsetX:(CGFloa)offsetX

即:当手指偏移时,根据x轴的偏移量算当前主视图的frame

getCurrentFrameWithOffsetX:(CGFloat)offsetX {

}

二、定位

touch方法

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent*)event

{

   //获取UITouch对象

   UITouch*touch = [touches anyObject];

   //获取当前点以及上一个点,并计算两点的偏移量

   CGPointpoint = [touch locationInView:self.view];

   CGPointprePoint = [touch previousLocationInView:self.view];

   CGFloatoffsetX = point.x- prePoint.x;

   //获取主视图的frame

   //CGRect frame = mainView.frame;

   //frame.origin.x += offsetX;

   _mainView.frame= [self getCurrentFrameWithOffsetX:offsetX];

   _isTarget=YES;;

}

效果图:

posted @ 2018-09-07 16:34  光是光光的光呐  阅读(359)  评论(0编辑  收藏  举报