It is hard to describe in plain text, so I recorded a GIF to demonstrate.
https://public.lightpic.info/image/2B1F_582465841.gif
I am currently working on a project that requires such effect. Up to now I have finished a similar effect on iOS with SpriteKit, however unfortunately it turns out the result is not pretty satisfying.
This is my work: in my project there is an object with an irregular shape, a constant force is applied at somewhere below the gravity center of the object and its direction is downward. I have made it a rule that the object's coordinate cannot be changed by the force, so that the object will not be pulled downwards by the force. When the object is tilted, its inertance and the force result an angular momentum, which makes the object upright. Details:
And when the object is being manipulated, the point of action is higher than the gravity center. As a result of combination of the object's inertance and the force, an angular momentum makes the object tilted.
However nothing has proven I am right, because the result I get from SpriteKit's physics engine is that, the object turns out to be a simple pendulum. But intuition tells me I was not wrong, in fact I did not pinned the object's gravity center to the background, and what I really did is to put the object back to the original position every time physics is simulated. But the result slapped my face really hard :(. Therefore, the pendulum swings and swings, the final physical effect just sucks.
Then I worked out a temporary solution: to multiply the angular velocity by 0.95 every time physics is simulated. This solution is clearly not the ideal one, because when the rotation angle tends to be horizontal, the angular velocity is not high enough and becomes upright slowly. However there is an advance: at least the object is able to stop swinging at last.
My further solution is that the force that is applied on the object changes with the tilt level. When the object tends to be horizontal, the force tends to be big, and when the object tends to be vertical, the force tends to be small. A simple function would describe it well: F=1000N×|sin[rotation degrees]|. This helps a lot, but unfortunately the result effect does not seem to be physical at all.
Conclusion: after many days’ study, I failed to implement the effect demonstrated in the GIF, and I feel very ashamed of that. I really hope anyone with great ability would help me. Thank you for reading my long description, I really appreciate your patience.
Addition:
There is a screenshot that shows my approach to implement this effect.
Addition 2:
I have uploaded my implementation, which is a Swift Playground file. Download it at: http://www.mediafire.com/file/qrct5sty2cyvwsy/Swing.playground.zip
PS. As my native language is not English, please forgive my poor grammar.