gpt4 book ai didi

iphone - 如何根据拖动角边的比例调整 UIView 的大小?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:43:29 25 4
gpt4 key购买 nike

我有一个具有一定尺寸的 UIView。我正在调整单击按钮时的 View 大小。但是 UIView 的大小调整取决于 3:2 、 4:3 、 16: 9 等比例。而且UIView的拖动一定要按照比例进行。

kResizeThumbSize 30

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
UITouch *touch = [[event allTouches] anyObject];

if ([((UIView *)(touch.view)) isEqual:canvas])
{
touchStart = [[touches anyObject] locationInView:canvas];
isResizingLR = (canvas.bounds.size.width - touchStart.x < kResizeThumbSize && canvas.bounds.size.height - touchStart.y < kResizeThumbSize);
isResizingUL = (touchStart.x <kResizeThumbSize && touchStart.y <kResizeThumbSize);
isResizingUR = (canvas.bounds.size.width-touchStart.x < kResizeThumbSize && touchStart.y<kResizeThumbSize);
isResizingLL = (touchStart.x <kResizeThumbSize && canvas.bounds.size.height -touchStart.y <kResizeThumbSize);
}

if(isResizingLR || isResizingUL|| isResizingLL || isResizingUR){
[canvas removeGestureRecognizer:panRecognizer];
}
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

CGPoint touchPoint = [[touches anyObject] locationInView:canvas];
CGPoint previous=[[touches anyObject]previousLocationInView:canvas];

float deltaWidth = touchPoint.x-previous.x;
float deltaHeight = touchPoint.y-previous.y;

if (isResizingLR) {
canvas.frame = CGRectMake(canvas.frame.origin.x, canvas.frame.origin.y,touchPoint.x + deltaWidth, touchPoint.y + deltaWidth);
}
if (isResizingUL) {
canvas.frame = CGRectMake(canvas.frame.origin.x + deltaWidth, canvas.frame.origin.y + deltaHeight, canvas.frame.size.width - deltaWidth, canvas.frame.size.height - deltaHeight);
}
if (isResizingUR) {
canvas.frame = CGRectMake(canvas.frame.origin.x ,canvas.frame.origin.y + deltaHeight, canvas.frame.size.width + deltaWidth, canvas.frame.size.height - deltaHeight);
}
if (isResizingLL) {
canvas.frame = CGRectMake(canvas.frame.origin.x + deltaWidth ,canvas.frame.origin.y , canvas.frame.size.width - deltaWidth, canvas.frame.size.height + deltaHeight);
}

}

最佳答案

你可以试试这个:

检查 deltaWidthdeltaHeight 中哪个的绝对值更大。它成为领先的尺寸,并按原样应用于框架。另一种是根据比率从 leading size delta 计算出来,然后应用于框架,忽略实际(较小)的 delta。

您可能还需要在初始 deltaWidthdeltaHeight 中应用比率检查,以更好地确定哪个变化更大。

关于iphone - 如何根据拖动角边的比例调整 UIView 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14109781/

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