源码下载地址:http://download.csdn.net/detail/liu537192/8544289
效果图:
核心代码:
//
// JLView.m
// View的拖拽
//
// Created by Mac on 15-3-29.
// Copyright (c) 2015年 vxinyou. All rights reserved.
//
#import "JLView.h"
@implementation JLView
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
// 当前触摸点
CGPoint currentPoint = [touch locationInView:self.superview];
// 上一个触摸点
CGPoint previousPoint = [touch previousLocationInView:self.superview];
// 当前view的中点
CGPoint center = self.center;
center.x += (currentPoint.x - previousPoint.x);
center.y += (currentPoint.y - previousPoint.y);
// 修改当前view的中点(中点改变view的位置就会改变)
self.center = center;
}
@end