public SwipeTransitionInteractionController(UIScreenEdgePanGestureRecognizer gestureRecognizer, UIRectEdge edge)
        {
            GestureRecognizer = gestureRecognizer;
            Edge = edge;

            GestureRecognizer.AddTarget(() => GestureRecognizeDidUpdate(GestureRecognizer));
        }
		public static void AddBorder(this UIView view, UIRectEdge edge, UIColor color, nfloat thickness) {

			var border = new CALayer ();
			var f = view.Frame;
			switch(edge)
			{
			case UIRectEdge.Top:
				border.Frame = new CGRect(0, 0, f.Width, thickness);
				break;
			case UIRectEdge.Bottom:
				border.Frame = new CGRect (0, f.Height - thickness, f.Width, thickness);
				break;
			case UIRectEdge.Left:
				border.Frame = new CGRect(0, 0, thickness, f.Height);
				break;
			case UIRectEdge.Right:
				border.Frame = new CGRect(f.Width - thickness, 0, thickness, f.Height);
				break;
			default:
				break;
			}

			border.BackgroundColor = color.CGColor;
			view.Layer.AddSublayer (border);
		}
Beispiel #3
0
        public static void AddBorder(this UIView view, UIRectEdge edge, UIColor color,
                                     nfloat thickness, float radius = 0.0f)
        {
            var border = new CALayer();
            var f      = view.Frame;

            switch (edge)
            {
            case UIRectEdge.Top:
                border.Frame = new CGRect(0, 0, f.Width, thickness);
                break;

            case UIRectEdge.Bottom:
                border.Frame = new CGRect(0, f.Height - thickness, f.Width, thickness);
                break;

            case UIRectEdge.Left:
                border.Frame = new CGRect(0, 0, thickness, f.Height);
                break;

            case UIRectEdge.Right:
                border.Frame = new CGRect(f.Width - thickness, 0, thickness, f.Height);
                break;

            default:
                break;
            }

            if (radius > 0)
            {
                border.CornerRadius = radius;
            }
            border.BackgroundColor = color.CGColor;
            view.Layer.AddSublayer(border);
        }
Beispiel #4
0
 public static void SetEdgesForExtendedLayout(
     this UIViewController viewController, UIRectEdge edgesForExtendedLayout = UIRectEdge.All)
 {
     if (viewController.RespondsToSelector(new Selector("setEdgesForExtendedLayout:")))
     {
         viewController.EdgesForExtendedLayout = edgesForExtendedLayout;
     }
 }
 /// <summary>
 /// Adds borders (as UIViews) to a view.
 /// </summary>
 /// <param name="view">The view to add the borders to.</param>
 /// <param name="edges">The edges to add borders to.</param>
 /// <param name="borderColor">The color of the borders.</param>
 /// <param name="thickness">The thickness of the borders.</param>
 public static void AddBordersToView(this UIView view, UIRectEdge edges, UIColor borderColor, float thickness = 1)
 {
     if (edges.HasFlag(UIRectEdge.Top) || edges.HasFlag(UIRectEdge.All))
     {
         var top = GetBorderView(borderColor);
         view.Add(top);
         view.AddConstraints(new[] {
             NSLayoutConstraint.Create(top, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1, -thickness),
             NSLayoutConstraint.Create(top, NSLayoutAttribute.Left, NSLayoutRelation.Equal, view, NSLayoutAttribute.Left, 1, 0),
             NSLayoutConstraint.Create(top, NSLayoutAttribute.Right, NSLayoutRelation.Equal, view, NSLayoutAttribute.Right, 1, 0),
             NSLayoutConstraint.Create(top, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, thickness)
         });
     }
     if (edges.HasFlag(UIRectEdge.Right) || edges.HasFlag(UIRectEdge.All))
     {
         var right = GetBorderView(borderColor);
         view.Add(right);
         view.AddConstraints(new[] {
             NSLayoutConstraint.Create(right, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1, 0),
             NSLayoutConstraint.Create(right, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1, 0),
             NSLayoutConstraint.Create(right, NSLayoutAttribute.Right, NSLayoutRelation.Equal, view, NSLayoutAttribute.Right, 1, thickness),
             NSLayoutConstraint.Create(right, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, thickness)
         });
     }
     if (edges.HasFlag(UIRectEdge.Bottom) || edges.HasFlag(UIRectEdge.All))
     {
         var bottom = GetBorderView(borderColor);
         view.Add(bottom);
         view.AddConstraints(new[] {
             NSLayoutConstraint.Create(bottom, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1, thickness),
             NSLayoutConstraint.Create(bottom, NSLayoutAttribute.Left, NSLayoutRelation.Equal, view, NSLayoutAttribute.Left, 1, 0),
             NSLayoutConstraint.Create(bottom, NSLayoutAttribute.Right, NSLayoutRelation.Equal, view, NSLayoutAttribute.Right, 1, 0),
             NSLayoutConstraint.Create(bottom, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, thickness)
         });
     }
     if (edges.HasFlag(UIRectEdge.Left) || edges.HasFlag(UIRectEdge.All))
     {
         var left = GetBorderView(borderColor);
         view.Add(left);
         view.AddConstraints(new[] {
             NSLayoutConstraint.Create(left, NSLayoutAttribute.Top, NSLayoutRelation.Equal, view, NSLayoutAttribute.Top, 1, 0),
             NSLayoutConstraint.Create(left, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, view, NSLayoutAttribute.Bottom, 1, 0),
             NSLayoutConstraint.Create(left, NSLayoutAttribute.Left, NSLayoutRelation.Equal, view, NSLayoutAttribute.Left, 1, -thickness),
             NSLayoutConstraint.Create(left, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, thickness)
         });
     }
 }
Beispiel #6
0
        public static UIView InsertSeparator(this UIView self, UIRectEdge edge = UIRectEdge.Bottom)
        {
            var thickness = 1 / UIScreen.MainScreen.Scale;
            var separator = new UIView();

            separator.BackgroundColor = ColorAssets.Separator;
            self.AddSubview(separator);

            separator.TranslatesAutoresizingMaskIntoConstraints = false;
            switch (edge)
            {
            case UIRectEdge.Top:
                separator.TopAnchor.ConstraintEqualTo(self.TopAnchor).Active     = true;
                separator.LeftAnchor.ConstraintEqualTo(self.LeftAnchor).Active   = true;
                separator.RightAnchor.ConstraintEqualTo(self.RightAnchor).Active = true;
                separator.HeightAnchor.ConstraintEqualTo(thickness).Active       = true;
                break;

            case UIRectEdge.Bottom:
                separator.BottomAnchor.ConstraintEqualTo(self.BottomAnchor, -thickness).Active = true;
                separator.LeftAnchor.ConstraintEqualTo(self.LeftAnchor).Active   = true;
                separator.RightAnchor.ConstraintEqualTo(self.RightAnchor).Active = true;
                separator.HeightAnchor.ConstraintEqualTo(thickness).Active       = true;
                break;

            case UIRectEdge.Left:
                separator.LeftAnchor.ConstraintEqualTo(self.LeftAnchor).Active     = true;
                separator.BottomAnchor.ConstraintEqualTo(self.BottomAnchor).Active = true;
                separator.TopAnchor.ConstraintEqualTo(self.TopAnchor).Active       = true;
                separator.WidthAnchor.ConstraintEqualTo(thickness).Active          = true;
                break;

            case UIRectEdge.Right:
                separator.RightAnchor.ConstraintEqualTo(self.RightAnchor).Active   = true;
                separator.BottomAnchor.ConstraintEqualTo(self.BottomAnchor).Active = true;
                separator.TopAnchor.ConstraintEqualTo(self.TopAnchor).Active       = true;
                separator.WidthAnchor.ConstraintEqualTo(thickness).Active          = true;
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(edge), edge, null);
            }

            return(separator);
        }
Beispiel #7
0
        public void HandlePresentMenuPan(UIPanGestureRecognizer pan)
        {
            // how much distance have we panned in reference to the parent view?
            var view = viewControllerForPresentedMenu != null ? viewControllerForPresentedMenu?.View : pan.View;

            if (view == null)
            {
                return;
            }

            var transform = view.Transform;

            view.Transform = CoreGraphics.CGAffineTransform.MakeIdentity();
            var translation = pan.TranslationInView(pan.View);

            view.Transform = transform;

            // do some math to translate this to a percentage based value
            if (!interactive)
            {
                if (translation.X == 0)
                {
                    return; // not sure which way the user is swiping yet, so do nothing
                }

                if (!(pan is UIScreenEdgePanGestureRecognizer))
                {
                    this.PresentDirection = translation.X > 0 ? UIRectEdge.Left : UIRectEdge.Right;
                }

                var menuViewController = SideMenuManager.LeftNavigationController;
                if (menuViewController != null && visibleViewController != null)
                {
                    interactive = true;
                    visibleViewController.PresentViewController(menuViewController, true, null);
                }
            }

            var direction = this.PresentDirection == UIRectEdge.Left ? 1 : -1;
            var distance  = translation.X / SideMenuManager.MenuWidth;

            // now lets deal with different states that the gesture recognizer sends
            switch (pan.State)
            {
            case UIGestureRecognizerState.Began:
            case UIGestureRecognizerState.Changed:
                if (pan is UIScreenEdgePanGestureRecognizer)
                {
                    this.UpdateInteractiveTransition((float)Math.Min(distance * direction, 1));
                }
                else if (distance > 0 && this.PresentDirection == UIRectEdge.Right && SideMenuManager.LeftNavigationController != null)
                {
                    this.PresentDirection = UIRectEdge.Left;
                    switchMenus           = true;
                    this.CancelInteractiveTransition();
                }
                else
                {
                    this.UpdateInteractiveTransition((float)Math.Min(distance * direction, 1));
                }
                break;

            default:
                interactive    = false;
                view.Transform = CGAffineTransform.MakeIdentity();
                var velocity = pan.VelocityInView(pan.View).X *direction;
                view.Transform = transform;
                if (velocity >= 100 || velocity >= -50 && Math.Abs(distance) >= 0.5)
                {
                    //TODO: Review this... Uses FLT_EPSILON
                    //// bug workaround: animation briefly resets after call to finishInteractiveTransition() but before animateTransition completion is called.
                    //if (NSProcessInfo.ProcessInfo.OperatingSystemVersion.Major == 8 && this.percentComplete > 1f - 1.192092896e-07F) {
                    //            this.updateInteractiveTransition(0.9999);
                    //}
                    this.FinishInteractiveTransition();
                }
                else
                {
                    this.CancelInteractiveTransition();
                }
                break;
            }
        }
Beispiel #8
0
 public void HandlePresentMenuRightScreenEdge(UIScreenEdgePanGestureRecognizer edge)
 {
     this.PresentDirection = UIRectEdge.Right;
     HandlePresentMenuPan(edge);
 }
 public SlideTransitionAnimator(UIRectEdge edge)
 {
     targetEdge = edge;
 }
 public static void SetEdgesForExtendedLayout(
     this UIViewController viewController, UIRectEdge edgesForExtendedLayout = UIRectEdge.All)
 {
     if (viewController.RespondsToSelector(new Selector("setEdgesForExtendedLayout:")))
         viewController.EdgesForExtendedLayout = edgesForExtendedLayout;
 }
Beispiel #11
0
 // This constructor aint probably needed.
 public MyPhoneMasterDetailRenderer(UIRectEdge edge)
 {
     swipeEdge = edge;
 }
Beispiel #12
0
 public override void ViewDidLoad()
 {
     base.ViewDidLoad();
     EdgesForExtendedLayout = new UIRectEdge();
 }
Beispiel #13
0
        /// <summary>
        ///     UIView with the colored border for target edges.
        /// </summary>
        /// <returns>UIView with border.</returns>
        /// <param name="view">Target view.</param>
        /// <param name="borderWidth">Border width.</param>
        /// <param name="borderColor">Border color.</param>
        /// <param name="edge">Border edge.</param>
        public static UIView WithBorder(this UIView view, nfloat borderWidth, CGColor borderColor, UIRectEdge edge)
        {
            if (edge == UIRectEdge.None)
            {
                return(view);
            }

            if (edge.HasFlag(UIRectEdge.All))
            {
                return(WithBorder(view, borderWidth, borderColor));
            }

            if (edge.HasFlag(UIRectEdge.Top))
            {
                AddBorder(
                    view,
                    borderColor,
                    UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleBottomMargin,
                    new CGRect(0, 0, view.Frame.Size.Width, borderWidth));
            }

            if (edge.HasFlag(UIRectEdge.Bottom))
            {
                AddBorder(
                    view,
                    borderColor,
                    UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin,
                    new CGRect(0, view.Frame.Size.Height - borderWidth, view.Frame.Size.Width, borderWidth));
            }

            if (edge.HasFlag(UIRectEdge.Left))
            {
                AddBorder(
                    view,
                    borderColor,
                    UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleRightMargin,
                    new CGRect(0, 0, borderWidth, view.Frame.Size.Height));
            }

            if (edge.HasFlag(UIRectEdge.Right))
            {
                AddBorder(
                    view,
                    borderColor,
                    UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleLeftMargin,
                    new CGRect(view.Frame.Size.Width - borderWidth, 0, borderWidth, view.Frame.Size.Height));
            }

            return(view);
        }
 public void SetPreferredScreenEdgesDeferringSystemGestures(UIRectEdge rectEdge)
 {
     preferredScreenEdgesDeferringSystemGestures = rectEdge;
     SetNeedsUpdateOfScreenEdgesDeferringSystemGestures();
 }