Giter Site home page Giter Site logo

draggableviewdemo's Introduction

DraggableViewDemo

这份代码能够让你轻松实现可拖动的视图。

使用方法:

1、下载并导入分类UIView+Draggable。

2、对需要拖动的控件设置draggingType。

支持继承于UIView的所有控件如UIButton、UITableView、ContainerView等。设置拖动后将优先响应拖动,继承于UIScrollView的控件如UITableView,UITextView等将无法滚动,拖动结束可通过设置draggingType=DraggingTypeDisabled来恢复UIScrollView的滚动事件。

支持autolayout,autosizing。被拖动的控件会自动移除边距约束。

支持代码,也支持interface builder。

可设置类型包括:

/**
 拖拽方式
 - DraggingTypeDisabled :不能拖拽
 - DraggingTypeNormal: 正常拖拽
 - DraggingTypeRevert: 释放后还原
 - DraggingTypePullOver: 自动靠边,只会靠左右两边
 - DraggingTypeAdsorb: 靠边时自动吸附边缘,可吸附四周
 */
typedef NS_ENUM(NSUInteger, DraggingType) {
    DraggingTypeDisabled,
    DraggingTypeNormal,
    DraggingTypeRevert,
    DraggingTypePullOver,
    DraggingTypeAdsorb,
};

可设置拖动范围

/**
 是否可只能在subView的范围内,默认是NO。
 
 @warning 如果NO,超出subView范围的部分无法响应拖拽。剪裁超出部分可直接使用superView.clipsToBounds=YES
 */
@property(nonatomic)BOOL draggingInBounds;

可主动操作View

/**
 主动靠边并吸附
 */
-(void)adsorbingAnimated:(BOOL)animated;

/**
 主动靠边
 */
-(void)pullOverAnimated:(BOOL)animated;

/**
 主动还原位置
 */
-(void)revertAnimated:(BOOL)animated;

可监听拖动事件以实现更多自定义功能

-(void)draggingDidBegan:(UIView *)view;
-(void)draggingDidChanged:(UIView *)view;
-(void)draggingDidEnded:(UIView *)view;

如果有什么不对的地方欢迎斧正。

draggableviewdemo's People

Contributors

anjohnlv avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.