我想根据pinchGestureRecognizer
捕获的用户的pinchGesture,增加或减少从原始帧的中心点扩展的绘制圆的大小。
到目前为止,我所遇到的问题是令人信服地展示了从中心出来的圈子的扩展。我可以让圆圈展开,但它似乎总是从左上角而不是中心扩展。我附上说明问题的屏幕截图:
以下是我绘制圆圈的代码:
int size = 120;
int radius = size/2;
self.tapSelectionView = [[UIView alloc] initWithFrame:CGRectMake(longPressedPoint.x - radius, longPressedPoint.y - radius, size, size)];
self.tapSelectionView.layer.cornerRadius = radius;
self.tapSelectionView.layer.borderColor = [UIColor greenColor].CGColor;
self.tapSelectionView.backgroundColor = [UIColor clearColor];
self.tapSelectionView.layer.borderWidth = 2;
[self.view addSubview:self.tapSelectionView];
CGPoint centerOfOriginalFrame = CGPointMake(self.tapSelectionView.frame.origin.x + radius, self.tapSelectionView.frame.origin.y + radius);
centerOfDrawnCircle = centerOfOriginalFrame;
在我的捏手势方法中,这就是我正在做的事情:
- (void)pinchGesture: (UIPinchGestureRecognizer *)pinchGestureRecognizer
{
int size = 120;
int radius = size/2;
self.tapSelectionView.layer.cornerRadius = pinchGestureRecognizer.scale * radius;
self.tapSelectionView.frame = CGRectMake(centerOfDrawnCircle.x - radius, centerOfDrawnCircle.y - radius, size * pinchGestureRecognizer.scale, size * pinchGestureRecognizer.scale);
}
谢谢!
答案 0 :(得分:1)
self.tapSelectionView.layer.cornerRadius = pinchGestureRecognizer.scale * radius;
self.tapSelectionView.frame = CGRectMake(centerOfDrawnCircle.x - radius * pinchGestureRecognizer.scale, centerOfDrawnCircle.y - radius * pinchGestureRecognizer.scale, size * pinchGestureRecognizer.scale, size * pinchGestureRecognizer.scale);