XiaoXiao1314_520 2015-04-27 06:05 采纳率: 0%
浏览 1763
已采纳

iOS 怎么重写UIView类的touchsBeguh方法

我要实现 点击屏幕记录点击的位置存放到单例数组中;
求解答;
求代码演示;

  • 写回答

1条回答 默认 最新

  • dlw222333 2015-04-27 08:10
    关注

    // 不知道是不是这个意思?
    #import "ViewController.h"

    @interface ViewController ()
    @property (nonatomic,copy)NSMutableArray *array;
    @end

    @implementation ViewController

    • (NSMutableArray *)array{ if (!_array) { _array = [NSMutableArray array]; } return _array; }
    • (void)viewDidLoad {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      }

    • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
      // 获取点击位置
      UITouch *touch = [touches anyObject];
      CGPoint p = [touch locationInView:self.view];
      NSLog(@"坐标:(%f,%f)",p.x,p.y);
      // 需要将CGPoint类型的坐标点转为 NSValue类型存放到数组中
      NSValue *pValue = [NSValue valueWithCGPoint:p];
      [self.array addObject: pValue];
      }
      @end

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?