您的位置:首页 > 产品设计 > UI/UE

UIView的拖拽

2016-03-03 21:15 344 查看
1.



2.
//
//  RedView.m

#import "RedView.h"

@implementation RedView

/**
*  当手指在View上移动就会调用
*/
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
// 取出UITouch对象
UITouch *touch = [touches anyObject];

// 获取当前触摸点
CGPoint currentP = [touch locationInView:self];

// 获取上一个触摸点
CGPoint previousP = [touch previousLocationInView:self];

// 获取偏移量
CGFloat offsetX = currentP.x - previousP.x;
CGFloat offsetY = currentP.y - previousP.y;

// 修改View的位置(frame\center\transform)
self.transform = CGAffineTransformTranslate(self.transform, offsetX, offsetY);
}

@end
演示效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: