开发者社区> 问答> 正文

请问iOS如何重写UIView类的touchsBeguh方法

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

展开
收起
爵霸 2016-03-13 10:04:55 1805 0
1 条回答
写回答
取消 提交回答
  • // 不知道是不是这个意思?
     #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
    
    
    2019-07-17 19:01:56
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载