UITouch和重力感应摇一摇
开始触摸时调用的方法
开始触摸时调用的方法
- (void)touchesBegan:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event{
UITouch * touch = [touches anyObject];
CGPoint point1 = [touch previousLocationInView:_view];
NSString * str = NSStringFromCGPoint(point1);
NSLog(@"上一次的坐标%@",str);
CGPoint point = [touch locationInView:_view];
str = NSStringFromCGPoint(point);
NSLog(@"当期坐标%@",str);
}
手指移动时调用的方法
- (void)touchesMoved:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
UITouch * touch = [touches anyObject]
//开始触摸的坐标
CGPoint point1 = [touch previousLocationInView:_view]
//当前的坐标
CGPoint point2 = [touch locationInView:_view]
NSString * str = NSStringFromCGPoint(point1)
NSLog(@"上一次的坐标%@",str)
str = NSStringFromCGPoint(point2)
NSLog(@"当期坐标%@",str)
//移动的距离
CGPoint point3 = CGPointMake(point2.x - point1.x, point2.y - point1.y)
_view.center = CGPointMake(_view.center.x + point3.x, _view.center.y + point3.y)
}
触摸结束时调用的方法
//触摸结束后调用的方法
- (void)touchesEnded:(nonnull NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event
{
NSLog(@"触摸结束");
}
重力感应摇一摇时候调用的方法
//开始摇动时调用的方法
- (void)motionBegan:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event
//结束摇动时调用的方法
- (void)motionEnded:(UIEventSubtype)motion withEvent:(nullable UIEvent *)event
-