我要实现 点击屏幕记录点击的位置存放到单例数组中;
求解答;
求代码演示;
// 不知道是不是这个意思?
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic,copy)NSMutableArray *array;
@end
@implementation ViewController
(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