gpt4 book ai didi

ios - 如何从框架的原始中心放大/缩小绘制的圆圈?

转载 作者:行者123 更新时间:2023-11-29 12:55:57 25 4
gpt4 key购买 nike

我想根据 pinchGestureRecognizer 捕获的用户 pinchGesture 来增大或减小从其原始框架的中心 点扩展的绘制圆的大小.

到目前为止,我遇到的问题是令人信服地展示圆从中心出来的扩展。我能够让圆圈扩大,但它总是看起来好像是从其左上角而不是中心扩大。我附上了说明问题的屏幕截图:

enter image description here enter image description here enter image description here

这是我绘制圆圈的代码:

    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);
}

谢谢!

最佳答案

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);

关于ios - 如何从框架的原始中心放大/缩小绘制的圆圈?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com