iOS控件 ----- UITouch相关

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
- 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值