HomeiOS Developmentios - Easy methods to apply non-uniform scaling to a rotated UIView...

ios – Easy methods to apply non-uniform scaling to a rotated UIView (rectangle) over Mapbox with out distortion?


I’m attempting to permit non-uniform scaling (horizontal or vertical) of a UIView rectangle that’s positioned over a Mapbox mapView and has already been rotated. Uniform scaling works properly, however once I try to use non-uniform scaling (scaling solely X or Y) utilizing transforms after rotation, the rectangle turns into distorted like a parallelogram.

To keep away from distortion, I as an alternative redraw the rectangle utilizing coordinate math on the finish of the gesture, however this makes the scaling really feel abrupt and never easy. I need to obtain easy, stay non-uniform scaling after rotation with out visible distortion. I’ve tried utilizing rework.scaledBy(x:y:), however it doesn’t preserve the rectangle’s orthogonality post-rotation.

How can I obtain easy, interactive, non-uniform scaling on a rotated view with out it deforming?

Code Snippets

Right here’s the pinchProcess gesture handler:

@objc func handlePinchGesture(_ recognizer: UIPinchGestureRecognizer) {
    guard isScalingEnabled, let targetView = self.scalingView else { return }

    if recognizer.state == .started {
        previousScale = 1.0
        initialPinchLocation = recognizer.location(in: targetView)
    }

    if recognizer.state == .ended || recognizer.state == .cancelled {
        if hasRotationApplied {
            gestureDelegate?.applyScalingAndRedraw(for: targetView, axis: lastScaleAxis, scaleFactor: finalScaleValue)
        } else {
            gestureDelegate?.finalizeSnap(for: targetView, usingPoints: originalPoints)
        }
        return
    }

    if recognizer.numberOfTouches 
func applyScalingAndRedraw(for view: UIView, axis: String, scaleFactor: CGFloat) {
    // Computes new factors based mostly on the scaling axis and applies redraw logic
    // Geometry strategies replace coordinates and redraw the rectangle appropriately
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments