Rotate Bar Based on Touch Drag

I want to rotate the bar based on my finger touch draw related to the pivot point. Following test structure implementation, I have created it for testing purposes.

Currently, I can able to write this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestRotateController : MonoBehaviour
{

    float rotateSpeed = 10f;
    Vector2 touchStartPos;
    Transform touchItem;
    //
    [SerializeField] LayerMask touchItemsMask;

    private void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);

            RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero, 0f, touchItemsMask);

            if (hit.collider != null && hit.transform.CompareTag(GameConstants.TAG_RELEASE_ANGLE_BAR))
            {
                touchItem = hit.transform;
                touchStartPos = mousePos2D;
            }
        }
        else if (Input.GetMouseButton(0))
        {

            if (touchItem != null && touchItem.CompareTag(GameConstants.TAG_RELEASE_ANGLE_BAR))
            {

                Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);

                RotateReleaseAngleBar(touchStartPos, mousePos2D);

            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            touchItem = null;
        }
    }

    // rotate pivot parent
    public void RotateReleaseAngleBar(Vector2 touchStartPosition, Vector2 touchPosition)
    {
        if (touchStartPosition.x > touchPosition.x)
        {
            transform.parent.Rotate(Vector3.forward, rotateSpeed * Time.deltaTime);
        }
        else if (touchStartPosition.x < touchPosition.x)
        {
            transform.parent.Rotate(Vector3.forward, -rotateSpeed * Time.deltaTime);
        }
    }
}

Now with this code, I can’t able to rotate the bar as my finger is moving. The selected direction will remain proper because I have used X value to decide this but when I stop dragging my finger then also rotation remains to continue in the same direction.

I want to stop this, I want to rotate the bar based on finger drag amount. It is a kind of experience, I want a person is rotating the bar with his finger.

Is this the type of thing you are looking for?
7389491--902123--HandleRotation.gif
If so, here is the script I came up with:

using UnityEngine;

public class TestRotateController : MonoBehaviour
{
    [SerializeField] private Collider2D m_Handle;
    private Quaternion? m_RotationOffset;

    private void Update()
    {

        if (Input.GetMouseButtonDown(0))
        {
            Vector2 mousePos = GetMousePosition();
            // Is mouse inside handle collider?
            if (m_Handle.OverlapPoint(mousePos))
                // Get offset rotation between up vector and mousePos
                m_RotationOffset = Quaternion.FromToRotation(GetDirectionFromPoint(mousePos), transform.up);
        }
        else if (Input.GetMouseButtonUp(0))
            m_RotationOffset = null;

        // If rotation offset is not null, do rotation
        if (m_RotationOffset != null)
        {
            // Debug draw offset rotation, no needed.
            Debug.DrawLine(transform.position, transform.position + Quaternion.Inverse(m_RotationOffset.Value) * transform.up, Color.cyan);
            // Look at cursor
            transform.rotation = Quaternion.LookRotation(Vector3.forward, GetDirectionFromPoint(GetMousePosition()));
            // Apply offset rotation
            transform.rotation *= m_RotationOffset.Value;
        }
    }

    private Vector2 GetMousePosition() => Camera.main.ScreenToWorldPoint(Input.mousePosition);
    private Vector2 GetDirectionFromPoint(Vector2 point) => point - (Vector2)transform.position;
}

Instead of you raycasting, I just check if the cursor overlaps the handle collider defined in the inspector. Of course raycasting is still a valid option, especially if you want a foreground object to block the interaction.