我要實現 點擊屏幕記錄點擊的位置存放到單例數組中;
求解答;
求代碼演示;
// 不知道是不是這個意思?
#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