Reputation: 5505
I would like to increase or decrease the size of a drawn circle that expands from the center point of its original frame based on a user's pinchGesture as captured by the pinchGestureRecognizer
.
So far, the issue I am having is convincing showcasing the expansion of the circle as it comes out from its center. I am able to get the circle to expand, but it always appears as if its expanding from its upper left corner as opposed to the center. I have attached screenshots illustrating the issue:
Here is my code that draws the circle:
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;
And in my pinch gesture method, this is what I am doing:
- (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);
}
Thanks!
Upvotes: 1
Views: 590
Reputation: 4792
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);
Upvotes: 1