[翻译] 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 ...
随机推荐
- hdu 3573(数学+贪心)
Buy Sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- WordPress插件:WP No Category Base 去除分类Category目录
不少折腾WordPress的朋友都希望去掉分类链接中的 /category/ 目录标志,网上很多这方面的教程,据倡萌所知,除了使用 WP No Category Base 插件(或类似插件),其他的方 ...
- Win + Linux下Source Insight 替代方案
需要阅读大量的系统源码,还有开源框架和好的源码等,需要寻求轻量,多快好省的editor, 最好有markdown语法的支持,支持重构,跳转调用,定义等... 自动补全... 目前看来,windows上 ...
- android Webview Html5 相关文章
Android WebView的使用集锦(支持Html5) http://blog.csdn.net/l_215851356/article/details/69239643 WebView详解与简单 ...
- Expert C Programming 阅读笔记(CH2)
P33 Bugs are by far the largest and most successful class of entity, with nearly a million known ...
- python3环境下面bytes类型转换成字典类型实例
场景:通过http://tool.chinaz.com/tools/httptest.aspx在线HTTP接口测试工具获取接口的返回信息 { "status": 0, " ...
- Templated Helper Methods(二)
1.Label and Display Elements 2.Whole-Model Templated Helpers 3.Using Metadata to Control Edi ...
- 利用nodeJs anywhere搭建本地服务器环境【转载】
首先去nodeJs官网下载最新版nodeJs https://nodejs.org/en/ 安装成功后win+r打开cmd 输入node -help 或者node -v查看是否安装成功 装好后 ...
- oracle创建简单的包
--规范 create or replace package test_pkg is --test_pkg为包名 procedure showMessage; --声明一个过程 function my ...
- karma+seajs
下面的介绍以karma能正常运行为前提,看karma系列文章:http://www.cnblogs.com/laixiangran/tag/Karma/ 目录结构 步骤 安装 npm install ...