斜对角抽屉式效果原理

斜对角抽屉效果

一、移动

第一步:

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:(CGFloat)off set X

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

getCurrentFrameWithOffsetX:(CGFloat)off set X{

二、定位

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;;

}


效果图:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容