//
// BallView.m
// UI13小球拖拽
//
// Created by focus on 2017/1/22.
// Copyright © 2017年 focus. All rights reserved.
//
#import "BallView.h"
@implementation BallView
- (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//在这方法里获取起点
//获取触摸对象 NSSet<UITouch是C++聚合方法
UITouch * touch = [touches anyObject];
//找到点击的点
self.startPoint = [touch locationInView:self];
}
- (void) touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//在这方法让小球动起来
//先获取触摸对象
UITouch * touch = [touches anyObject];
//获取移动中的点
CGPoint newPoint = [touch locationInView:self];
//计算X Y坐标分别移动多少
CGFloat dx = newPoint.x - self.startPoint.x;
CGFloat dy = newPoint.y - self.startPoint.y;
// 改变小球的位置
self.center =CGPointMake(self.center.x+dx, self.center.y+dy);
}
- (void) touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/