Scaling UIView in one direction with UIPinchGestureRecognizer

In my application, I have draggable UIViewto which I added UIPinchGestureRecognizer. Following this tutorial, by default, the view scales along the x and y directions. Is it possible to scale only one direction using one finger? I mean, for example, I press with UIViewboth fingers and index fingers, as usual, but as long as I hold my thumb, I could only move the index finger in one direction, and then it UIViewshould scale along this measurement depending on in the direction in which the index moves.

Actually, I achieved this by adding pins to mine UIViewas follows:

enter image description here

, UIPinchGestureRecognizer.

, , - , .

+4
1

CGAffineTransformScale(view.transform, recognizer.scale, recognizer.scale) : X Y recognizer.scale 1.0f

CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)

, , , , , .

-

enum Axis {
    case X
    case Y
}

func axisFromPoints(p1: CGPoint, _ p2: CGPoint) -> Axis {
    let absolutePoint = CGPointMake(p2.x - p1.x, p2.y - p1.y)
    let radians = atan2(Double(absolutePoint.x), Double(absolutePoint.y))

    let absRad = fabs(radians)

    if absRad > M_PI_4 && absRad < 3*M_PI_4 {
        return .X
    } else {
        return .Y
    }
}
+5

Source: https://habr.com/ru/post/1620308/


All Articles