https://github.com/patridge/uigravitybehaviorrecipe
https://github.com/patridge/uigravitybehaviorrecipe
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/patridge/uigravitybehaviorrecipe
- Owner: patridge
- License: mit
- Created: 2013-09-25T04:15:59.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2019-02-19T19:52:40.000Z (over 6 years ago)
- Last Synced: 2025-01-01T10:25:24.754Z (5 months ago)
- Language: C#
- Size: 78.1 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Xamarin.iOS UIGravityBehavior Recipe
[See my blog for a [full write-up of this Xamarin UIGravityBehavior recipe](http://pdev.co/1gYRs1W).]
Playing with the new UIKit Dynamics `UIGravityBehavior`. Get a feel for the basic application of gravity with `BasicGravityViewController`.
UIDynamicAnimator animator;
public override void ViewDidLoad() {
base.ViewDidLoad();
View.BackgroundColor = UIColor.White;
animator = new UIDynamicAnimator(View);var item = new UIView(new RectangleF(new PointF(50f, 0f), new SizeF(50f, 50f))) {
BackgroundColor = UIColor.Blue,
};
View.Add(item);
UIGravityBehavior gravity = new UIGravityBehavior(item);
animator.AddBehavior(gravity);
}
Then, play around with changing gravity in `ChangingGravityViewController`.
View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
gravity.GravityDirection = new CGVector(1, 0);
}) { Direction = UISwipeGestureRecognizerDirection.Right, });
View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
gravity.GravityDirection = new CGVector(-1, 0);
}) { Direction = UISwipeGestureRecognizerDirection.Left, });
View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
gravity.GravityDirection = new CGVector(0, -1);
}) { Direction = UISwipeGestureRecognizerDirection.Up, });
View.AddGestureRecognizer(new UISwipeGestureRecognizer((gesture) => {
gravity.GravityDirection = new CGVector(0, 1);
}) { Direction = UISwipeGestureRecognizerDirection.Down, });