[翻译] 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.h
in 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 ...
随机推荐
- PHP安全编程:register_globals的安全性
如果你还能记起早期Web应用开发中使用C开发CGI程序的话,一定会对繁琐的表单处理深有体会.当PHP的register_globals配置选项打开时,复杂的原始表单处理不复存在,公用变量会自动建立.它 ...
- 洛谷 P1202 [USACO1.1]黑色星期五Friday the Thirteenth 题解
题目传送门 这道题暴力就能解决. #include<bits/stdc++.h> using namespace std; int xi; ,ans[]; int main() { int ...
- 洛谷 P2036 Perket 题解
题目传送门 这道题可以使用dfs深搜实现,在每次递归深搜时要更新ans. #include<bits/stdc++.h> using namespace std; ,s=,b; ]; st ...
- EasyUi – 1.入门
1.页面引用. jquery,easyui,主题easyui.css,图标ico.css,语言zh_CN.js <script src="Scripts/jquery-easyui-1 ...
- day3 集合set()实例分析
集合,我们在高中的时候专门学习过集合,并集,交集,差集等,下面来看一下集合的定义,如下: 集合(简称集)是数学中一个基本概念,它是集合论的研究对象,集合论的基本理论直到19世纪才被创立.最简单 ...
- BFS迷宫搜索路径
#include<graphics.h> #include<stdlib.h> #include<conio.h> #include<time.h> # ...
- poj2243 Knight Moves(BFS)
题目链接 http://poj.org/problem?id=2243 题意 输入8*8国际象棋棋盘上的两颗棋子(a~h表示列,1~8表示行),求马从一颗棋子跳到另一颗棋子需要的最短路径. 思路 使用 ...
- golang中接口interface和struct结构类的分析
再golang中,我们要充分理解interface和struct这两种数据类型.为此,我们需要优先理解type的作用. type是golang语言中定义数据类型的唯一关键字.对于type中的匿名成员和 ...
- markdown入门语法
目录 一: 标题 二:字体 三: 引用 四:分割线 五:图片 六:超链接 七:列表 九: 代码块 一: 标题 # 一级标题 ## 二级标题 ####### 最大六级标题 二:字体 1. 加粗字体 加粗 ...
- COMP COMP-3
Comp (Computational) Comp (with no suffix) leaves the choice of the data type to the compiler writer ...