我要实现 点击屏幕记录点击的位置存放到单例数组中;
求解答;
求代码演示;
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
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报