gpt4 book ai didi

ios - UIView 的特定部分放大/缩小而不增加 View objective C iOS 的高度/宽度

转载 作者:行者123 更新时间:2023-11-28 19:29:06 25 4
gpt4 key购买 nike

我实现了这个。但问题是它通过缩放增加了 View 的高度/宽度。如何在不增加高度/宽度的情况下进行缩放。我的 UIView 高度/宽度是固定的。我的基本目标是 View 高度/宽度保持不变但缩放 View 的内侧。

    UIPinchGestureRecognizer * pinGeture =  [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(twoFingerPinch:)];
[radarViewHolder addGestureRecognizer:pinGeture];



- (void)twoFingerPinch:(UIPinchGestureRecognizer *)recognizer
{
NSLog(@"Pinch scale: %f", recognizer.scale);

if([recognizer state] == UIGestureRecognizerStateBegan) {
// Reset the last scale, necessary if there are multiple objects with different scales
lastScale = [recognizer scale];
}

if ([recognizer state] == UIGestureRecognizerStateBegan ||
[recognizer state] == UIGestureRecognizerStateChanged) {

CGFloat currentScale = [[[recognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];

// Constants to adjust the max/min values of zoom
const CGFloat kMaxScale = 2.0;
const CGFloat kMinScale = 1.0;

CGFloat newScale = 1 - (lastScale - [recognizer scale]);
newScale = MIN(newScale, kMaxScale / currentScale);
newScale = MAX(newScale, kMinScale / currentScale);
CGAffineTransform transform = CGAffineTransformScale([[recognizer view] transform], newScale, newScale);
[recognizer view].transform = transform;

lastScale = [recognizer scale]; // Store the previous scale factor for the next pinch gesture call
}
}

最佳答案

在 yourScroll 中添加您的 View 作为 subview 。

[yourScroll addSubView:radarViewHolder];


- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{

CGFloat size = scrollView.zoomScale;
if (size > ZoomMaxValue)
{
yourScroll.zoomScale = maximumScale;
}
if (size > ZoomMinValue && size < ZoomValue && size < 1.01)
{
yourScroll.zoomScale = minimumScale;
}
ZoomValue = size;
}

关于ios - UIView 的特定部分放大/缩小而不增加 View objective C iOS 的高度/宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47926278/

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