iOS之Touch系统

Touch系统主要有一下几种方法

//懒加载
- (UIImageView *)imageView{
    if (!_imageView) {
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 70, self.view.bounds.size.width-40, self.view.bounds.size.height/2)];
        _imageView.image = [UIImage imageNamed:@"1.jpg"];

    }

    return _imageView;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.view addSubview:self.imageView];//名字和懒加载名字要相同,相当于调用方法



}

//NSSet,跟数组差不多,只不过NSSet集合中不能存放相同的元素,并且存入到集合中的元素是无序的
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    _imageView.frame = self.view.bounds;
    //不间断时间内连续点击次数
    UITouch *touch = [touches anyObject];
    NSLog(@"tapCount = %lu",touch.tapCount);

    NSLog(@"touch.timestamp = %f",touch.timestamp);

    NSLog(@"%lu",event.allTouches.count);//手指数

    //找出(单一)手指在屏幕的位置
    CGPoint point = [touch locationInView:self.view];

    NSLog(@"%@",NSStringFromCGPoint(point));//[NSValue valueWithCGPoint:point];

//    NSLog(@"开始");
    //遍历allTouches(集合),把所有手指坐标都打印出来
    for (UITouch *t in event.allTouches) {
        CGPoint point = [t locationInView:self.view];
        NSLog(@"%@",NSStringFromCGPoint(point));
    }

}

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    NSLog(@"移动");
    for (UITouch *t in event.allTouches) {
        CGPoint point = [t locationInView:self.view];
        NSLog(@"%@",NSStringFromCGPoint(point));
    }


}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    NSLog(@"取消");

}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    _imageView.frame = CGRectMake(50, 100, self.view.bounds.size.width-100, self.view.bounds.size.height/2);
    NSLog(@"结束");

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值