private void FlyTheShirt(PointF startPoint)
{
// Reset starting point of the ImageView
ivFlyingShirt.Frame = new RectangleF(startPoint.X, startPoint.Y, ivFlyingShirt.Frame.Width, ivFlyingShirt.Frame.Height);
NSMatrix matrix = (NSMatrix)btnNavigationProducts.ControlView;
int lastRowIndex = matrix.Rows - 1;
// Assuming the shopping basket button is always the last in the list...
var btnFrame = matrix.CellFrameAtRowColumn (lastRowIndex, 0);
var btnCenter = new PointF (btnFrame.Left + (btnFrame.Width / 2), btnFrame.Top + (btnFrame.Height / 2));
var btnCenterCompensated = new PointF (btnCenter.X - (ivFlyingShirt.Frame.Width / 2), btnCenter.Y + (ivFlyingShirt.Frame.Height / 2));
var endPoint = matrix.ConvertPointToView (btnCenterCompensated, matrix.Superview);
// Create quadratic curve path
var path = new CGPath ();
path.MoveToPoint (startPoint);
// Use the view title label as the control point for the curve
var controlPoint = lblViewTitle.Superview.ConvertPointToView(new PointF(lblViewTitle.Frame.Left + (lblViewTitle.Frame.Width/3), lblViewTitle.Frame.Bottom), null);
path.AddQuadCurveToPoint (controlPoint.X, controlPoint.Y, endPoint.X, endPoint.Y);
// Create animation based on the path and add it to the image view
var pathAnimation = CAKeyFrameAnimation.GetFromKeyPath ("frameOrigin");
pathAnimation.Path = path;
pathAnimation.RepeatCount = 0f;
pathAnimation.Duration = 0.7f;
pathAnimation.TimingFunction = CAMediaTimingFunction.FromName (CAMediaTimingFunction.EaseInEaseOut);
pathAnimation.AnimationStarted += delegate {
// Show the ImageView
ivFlyingShirt.Hidden = false;
};
pathAnimation.AnimationStopped += delegate {
// Hide the ImageView
ivFlyingShirt.Hidden = true;
badgeView.BadgeNumber = WebService.Shared.CurrentOrder.Products.Count;
};
ivFlyingShirt.Animations = NSDictionary.FromObjectAndKey (pathAnimation, (NSString)"frameOrigin");
// Change the frame location via animation
((NSImageView) ivFlyingShirt.Animator).Frame = new RectangleF(endPoint, ivFlyingShirt.Frame.Size);
}