3

我有一些大小的 UIView。我正在调整单击按钮的视图大小。但是 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);
    }

}
4

1 回答 1

0

你可以试试这个:

检查哪个deltaWidthdeltaHeight的绝对值更大。它成为前导大小并按原样应用于框架。另一个是根据比率从前导大小增量计算出来的,然后应用于帧,而实际(较小)增量被忽略。

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

于 2013-01-01T10:58:09.957 回答