zoukankan      html  css  js  c++  java
  • 触摸方法

      • #pragma mark 开始触摸
      • - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
      • {
      •     // 获取第一个触摸的点
      •         UITouch *touch = [touches anyObject];
      •     // 获取这点相对于window坐标
      •         CGPoint point = [touch locationInView:self.window];
      •     // 将x轴与y轴差值赋值给实例变量
      •         _x = point.x - self.center.x;
      •         _y = point.y - self.center.y;
      • }
      • #pragma mark 触摸过程中
      • - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
      • {
      •    // 1. 在集合中取出触摸的点
      •     UITouch *touch = [touches anyObject];
      •    // 2. 获取这个点坐标信息  (针对window或者自身)
      •     CGPoint point = [touch locationInView:self.window];
      •     NSLog(@"%@", NSStringFromCGPoint(point));
      •     CGFloat x = point.x - _x;
      •     CGFloat y = point.y - _y;
      •     self.center = CGPointMake(x, y);    // 中心点坐标
      • }
      • #pragma mark 触摸结束
      • - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
      • {
      •     NSLog(@"%d %s", __LINE__, __FUNCTION__);
      •     CGFloat red = (arc4random() % 256) / 255.0;
      •     CGFloat green = (arc4random() % 256) / 255.0;
      •     CGFloat blue = (arc4random() % 256) / 255.0;
      •     self.backgroundColor = [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
      • }
      • #pragma mark 触摸被取消
      • - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
      • {
      •     NSLog(@"%d %s", __LINE__, __FUNCTION__);
      • }
  • 相关阅读:
    SSH出现Connection refused错误
    Lisp经典算法
    Arch Linux下韩文重叠显示
    Vim在图形环境下全屏产生黑边
    Vim常用插件安装及配置方法
    Python中Scrapy框架元素选择器XPath的简单实例
    Manjaro下Steam无法启动
    GNOME禁用GDM中night-light功能
    Neovim中提示Error: Required vim compiled with +python
    Manjaro下带供电的USB Hub提示error -71
  • 原文地址:https://www.cnblogs.com/masami521/p/4726366.html
Copyright © 2011-2022 走看看