宽容他人,放过自己。

在点击点的位置创建控件_位置获取方法

Posted on By anchoriteFili

方法

UITouch *touch = [touches anyObject];
imageView.center = [touch locationInView:self.view];
#pragma mark 点击创建心模拟
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    UITouch *touch = [touches anyObject];
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    imageView.image = [UIImage imageNamed:@"test"];
    [self.view addSubview:imageView];
    imageView.center = [touch locationInView:self.view];
}