//
// CLTranslationView.m
// LessonUIEvent
//
// Created by lanouhn on 14-8-25.
// Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved.
//
#import "CLTranslationView.h"
@interface CLTranslationView ()
{
CGPoint _previousPoint;//存储移动之前的点的位置
}
@end
@implementation CLTranslationView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//用来设置当前视图是否支持多点触摸. iOS虽然支持多次触摸, 但是默认的是单点触摸
self.multipleTouchEnabled = YES;
}
return self;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%lu", (unsigned long)touches.count);
UITouch *touch = [touches anyObject];
//获取手指触摸在视图上的位置
_previousPoint = [touch locationInView:self];
//膨胀检测 有大到小
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
//获取手指对象
UITouch *touch = [touches anyObject];
//获取移动之后手指在视图上的位置
CGPoint currentPoint = [touch locationInView:self];
//获取移动之前和移动之后的坐标变化量
CGFloat dx = currentPoint.x - _previousPoint.x;
CGFloat dy = currentPoint.y - _previousPoint.y;
self.center = CGPointMake(self.center.x + dx, self.center.y + dy);
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end