[翻译] UIView-draggable 可拖拽的UIView
UIView-draggable 可拖拽的UIView

https://github.com/andreamazz/UIView-draggable
UIView category that adds dragging capabilities
一个类目用来给UIView便利的添加拖拽手势

Setup with Cocoapods 用Cocoapods设置
- Add
pod 'UIView+draggable'to your Podfile - Run
pod install - Run
open App.xcworkspace - Import
UIVIew+draggable.hin your controller's header file
Usage 使用
// Enable dragging
[self.view enableDragging];
TODO
- Write the README :)
UIView+draggable.h
//
// UIView+draggable.h
// UIView+draggable
//
// Created by Andrea on 13/03/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
// @interface UIView (draggable) /**-----------------------------------------------------------------------------
* @name UIView+draggable Properties
* -----------------------------------------------------------------------------
*/ /** The pan gestures that handles the view dragging
*
* @param panGesture The tint color of the blurred view. Set to nil to reset.
*/
@property (nonatomic) UIPanGestureRecognizer *panGesture; /**-----------------------------------------------------------------------------
* @name UIView+draggable Methods
* -----------------------------------------------------------------------------
*/ /** Enables the dragging
*
* Enables the dragging state of the view
*/
- (void)enableDragging; /** Disable or enable the view dragging
*
* @param draggable The boolean that enables or disables the draggable state
*/
- (void)setDraggable:(BOOL)draggable; @end
UIView+draggable.m
//
// UIView+draggable.m
// UIView+draggable
//
// Created by Andrea on 13/03/14.
// Copyright (c) 2014 Fancy Pixel. All rights reserved.
// #import "UIView+draggable.h"
#import <objc/runtime.h> @implementation UIView (draggable) - (void)setPanGesture:(UIPanGestureRecognizer*)panGesture
{
objc_setAssociatedObject(self, @selector(panGesture), panGesture, OBJC_ASSOCIATION_RETAIN);
} - (UIPanGestureRecognizer*)panGesture
{
return objc_getAssociatedObject(self, @selector(panGesture));
} - (void)handlePan:(UIPanGestureRecognizer*)sender
{
[self adjustAnchorPointForGestureRecognizer:sender]; CGPoint translation = [sender translationInView:[self superview]];
[self setCenter:CGPointMake([self center].x + translation.x, [self center].y + translation.y)]; [sender setTranslation:(CGPoint){, } inView:[self superview]];
} - (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UIView *piece = self;
CGPoint locationInView = [gestureRecognizer locationInView:piece];
CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview]; piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height);
piece.center = locationInSuperview;
}
} - (void)setDraggable:(BOOL)draggable
{
[self.panGesture setEnabled:draggable];
} - (void)enableDragging
{
self.panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
[self.panGesture setMaximumNumberOfTouches:];
[self.panGesture setMinimumNumberOfTouches:];
[self.panGesture setCancelsTouchesInView:NO];
[self addGestureRecognizer:self.panGesture];
} @end
[翻译] UIView-draggable 可拖拽的UIView的更多相关文章
- iOS边练边学--触摸事件以及能够拖拽的UIView的练习
一.用户在使用APP的过程中,会产生各种各样的事件.iOS中的事件可以分为3大类型: 二.响应者对象 在iOS中只有继承了了UIResponder的对象才能接受并处理事件,这样的对象称之为“响应者对象 ...
- Vue.Draggable实现拖拽效果(采坑小记)
之前有写过Vue.Draggable实现拖拽效果(快速使用)(http://www.cnblogs.com/songdongdong/p/6928945.html)最近项目中要用到这个拖拽的效果,当产 ...
- flutter Draggable Widget拖拽控件
Draggable Widget Draggable控件负责就是拖拽,父层使用了Draggable,它的子元素就是可以拖动的,子元素可以实容器,可以是图片.用起来非常的灵活. 参数说明: data: ...
- vue draggable 火狐拖拽搜索问题
最近在使用vuedraggable做导航时候,谷歌拖拽是没问题的,但是在火狐测试时候,拖拽时候是可以成功,但是火狐还是打开了一个新的tab,并且搜索了,一开始想着是阻止默认行为,但是在@end时间中阻 ...
- Vue.Draggable实现拖拽效果(快速使用)
1.下载包:npm install vuedraggable 配置:package.json "dependencies": { "element-ui": & ...
- JQUERY 拖拽 draggable droppable resizable selectable sortable
今天用了jq ui的拖动碰撞功能,好不容易看到有详细的API解说,记录如下: <script language="JavaScript" type="text/ ...
- jQuery UI API - 可拖拽小部件(Draggable Widget)(转)
所属类别 交互(Interactions) 用法 描述:允许使用鼠标移动元素. 版本新增:1.0 依赖: UI 核心(UI Core) 部件库(Widget Factory) 鼠标交互(Mouse I ...
- jquery 实现页面拖拽并保存到cookie
实现的效果就是页面内的图片可拖拽到任意位置,并将所在位置保存.下次打开页面依然可见.本文是作demo用,实际开发中,位置的数据应保存到数据库中. 好了,开始. 1.准备工作. a.jquery(1.7 ...
- sortable.js 拖拽排序及配置项说明
// 拖动排序 $(function() { /*排序*/ //排序 // Simple list ]; new Sortable(list, { group: "name", a ...
随机推荐
- CSRF攻击的应对之道
CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的攻击方式,该攻击可以在受害者毫不知情的情况下以受害者名义伪造请求发送给受攻击站点,从而在并未授权的情况下执 ...
- Windows内核读书笔记——SEH结构化异常处理
SEH是对windows系统中的异常分发和处理机制的总称,其实现分布在很多不同的模块中. SEH提供了终结处理和异常处理两种功能. 终结处理保证终结处理块中的程序一定会被执行 __try { //要保 ...
- MP3 Music Library in Tornado
Web2.0的lab3,使用tornado实现,自己改了改UI 效果 选中播放列表后的效果 原来的图标长得太丑了,有空找些好看点的加进去……以后继续完成extra feature,当复习python了 ...
- Ubuntu下Node.js开发起步之旅
因为忙其它的事,把Node.js的学习放下了快两个月了,世事变化还真快,发现很多东东都改变了,express已经升级到4.x了,变化还不小! 我原来的学习过程是在VirtualBox中安装Ubuntu ...
- 七 oracle 表查询二
1.使用逻辑操作符号问题:查询工资高于500或者是岗位为manager的雇员,同时还要满足他们的姓名首字母为大写的J?select * from emp where (sal > 500 or ...
- HTTP权威指南读书笔记(一)HTTP概述、URL和资源及报文详解
一.HTTP概述 1.WEB客户端和服务器. 2.资源:资源可以是各种格式的静态文件,也可以是应用程序. 3.媒体类型 4.URI:统一资源标识符 URL:统一资源定位符. URL的第一部分称为方案: ...
- 【.NET】学习SQLite(1)
前沿 SQLite,是一款轻型的数据库,是遵守ACID的关系型数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存 ...
- Coding.net简单使用指南
注意:大家创建项目时一定要选择创建公开仓库!不然别人看不到! Coding.net是一个代码托管平台,简单来说这东西就是一个你在线存放代码的地方. 至于为什么要把代码存到这东西上呢?很多好处,比如防丢 ...
- python每天定时发送短信脚本
最近业务上需要每天解析txt文本或者excel文件,读取内容发送短信,发送的时间段可控,用python实现 安装pip依赖 pip install -r requirement.txt xlrd Py ...
- innerText和innerHTML, outerHTML
js中 innerHTML与innerText的用法与区别及解决Firefox不支持Js的InnerHtml问题 用法: <div id="test"> <spa ...