private void PanGesture(UIPanGestureRecognizer pPan) { if (pPan.State == UIGestureRecognizerState.Ended) { if (Math.Abs(_PanStartOffset.X) < 0.001) { if (pPan.VelocityInView(this).X > 1000) { ChangeGraph(-1); } else if (pPan.VelocityInView(this).X < -1000) { ChangeGraph(1); } } } else if (pPan.State == UIGestureRecognizerState.Began) { _PanStartOffset = _Offset; } else if (pPan.State == UIGestureRecognizerState.Changed) { _Offset = pPan.TranslationInView(null).ToSKPoint() + _PanStartOffset; if (_Offset.X > 0) { _Offset = new SKPoint(0, _Offset.Y); } if (_Offset.Y > 0) { _Offset = new SKPoint(_Offset.X, 0); } SetNeedsDisplay(); } //pPan. }
private void HandlePan(UIPanGestureRecognizer rec) { if (rec.State == UIGestureRecognizerState.Began) { HandleTouchesBeganAtLocation(rec.LocationInView(View)); } else if (rec.State == UIGestureRecognizerState.Changed) { HandleTouchesMovedToLocation(rec.LocationInView(View)); } else if (rec.State == UIGestureRecognizerState.Ended || rec.State == UIGestureRecognizerState.Cancelled || rec.State == UIGestureRecognizerState.Failed) { float velocity = rec.VelocityInView(View).X; if (Math.Abs(velocity) > kLWMinimumVelocityToTriggerSlide) { if (velocity > 0f) { SlideOutSlideNavigationView(); } else { SlideInSlideNavigationView(); } } else { HandleTouchesEndedAtLocation(rec.LocationInView(View)); } } }
private void HandlePanFrom(UIPanGestureRecognizer recognizer) { if (recognizer.State == UIGestureRecognizerState.Began) { PointF touchLocation = recognizer.LocationInView(recognizer.View); touchLocation = this.ConvertPointFromView(touchLocation); this.SelectNodeForTouch(touchLocation); } else if (recognizer.State == UIGestureRecognizerState.Changed) { PointF translation = recognizer.TranslationInView(recognizer.View); translation = new PointF(translation.X, -translation.Y); this.PanForTranslation(translation); recognizer.SetTranslation(new PointF(0, 0), recognizer.View); } else if (recognizer.State == UIGestureRecognizerState.Ended) { float scrollDuration = 0.2f; if (this.SelectedNode.Name != ANIMAL_NODE_NAME) { PointF velocity = recognizer.VelocityInView(recognizer.View); PointF p = mult(velocity, scrollDuration); PointF position = this.SelectedNode.Position; PointF newPos = new PointF(position.X + p.X, position.Y + p.Y); newPos = this.BoundLayerPosition(newPos); this.SelectedNode.RemoveAllActions(); SKAction moveTo = SKAction.MoveTo(newPos, scrollDuration); moveTo.TimingMode = SKActionTimingMode.EaseOut; this.SelectedNode.RunAction(moveTo); } } }
protected void HandlePan(UIPanGestureRecognizer gesture) { // Prepare values UIView topView = this.TopViewController.View; float translationX = gesture.TranslationInView(this.View).X; float velocityX = gesture.VelocityInView(this.View).X; // Handle gesture switch (gesture.State) { case UIGestureRecognizerState.Began: { this.SlidingTransition.PanBegan(this, topView, translationX, velocityX); break; } case UIGestureRecognizerState.Changed: { this.SlidingTransition.PanChanged(this, topView, translationX, velocityX); break; } case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: { this.SlidingTransition.PanEnded(this, topView, translationX, velocityX); break; } } }
private void HandlePanGesture(UIPanGestureRecognizer recognizer) { var translation = recognizer.TranslationInView(recognizer.View); //distance of pan gestire from start position var distance = translation.X / UIScreen.MainScreen.Bounds.Width * -1; switch (recognizer.State) { case UIGestureRecognizerState.Began: _panGestureIsActive = true; MainViewController.DismissViewController(true, null); break; case UIGestureRecognizerState.Changed: var update = Math.Max(Math.Min((float)distance, 1.0f), 0.0f); UpdateInteractiveTransition(update); break; default: _panGestureIsActive = false; var velocity = recognizer.VelocityInView(recognizer.View).X * -1; if (velocity >= 100 || velocity >= -50 && distance >= 0.5) { FinishInteractiveTransition(); } else { CancelInteractiveTransition(); } break; } }
private void PanGesture(UIPanGestureRecognizer recognizer) { var translation = recognizer.TranslationInView(View); var y = View.Frame.GetMinY(); View.Frame = new CGRect(0, y + translation.Y, View.Frame.Width, View.Frame.Height); recognizer.SetTranslation(CGPoint.Empty, View); var velocity = recognizer.VelocityInView(View); if ((y + translation.Y >= fullView) & (y + translation.Y <= partialView)) { View.Frame = new CGRect(0, y + translation.Y, View.Frame.Width, View.Frame.Height); recognizer.SetTranslation(CGPoint.Empty, View); } if (recognizer.State == UIGestureRecognizerState.Ended) { var duration = velocity.Y < 0 ? ((y - fullView) / -velocity.Y) : ((partialView - y) / velocity.Y); duration = duration > 1.3 ? 1 : duration; UIView.Animate(duration, 0.0, UIViewAnimationOptions.AllowUserInteraction, () => { if (velocity.Y >= 0) { View.Frame = new CGRect(0, partialView, View.Frame.Width, View.Frame.Height); } else { View.Frame = new CGRect(0, fullView, View.Frame.Width, View.Frame.Height); } }, null); } }
public NodeTouchEvent(NodeUIView parent, UIPanGestureRecognizer pan) { switch (pan.State) { case UIGestureRecognizerState.Began: type = TouchType.Down; break; case UIGestureRecognizerState.Changed: type = TouchType.Move; break; case UIGestureRecognizerState.Ended: type = TouchType.Up; break; case UIGestureRecognizerState.Possible: case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: break; } var p = pan.LocationInView(parent); point = new Point(p.X, p.Y); var velo = pan.VelocityInView(parent); velocity = new Vec2(velo.X / 1000, velo.Y / 1000); }
/// <summary> /// Adjusts the size of the view when the user pans (if <see cref="AllowsManualResize"/> is <value>true</value>). /// </summary> /// <param name="recognizer">Gesture recognizer that is handling user interaction.</param> private void HandleMoveView(UIPanGestureRecognizer recognizer) { // Do nothing if user resize isn't enabled if (!AllowsManualResize) { return; } // Get the distance moved var translation = recognizer.TranslationInView(View); // In compact width scrolling up (negative translation) increases height as the card moves up if (TraitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular) { // translate height constraint _heightConstraint.Constant += translation.Y; } else { // translate height constraint _heightConstraint.Constant -= translation.Y; } // Prevent making the view too large if (_heightConstraint.Constant > MaxHeightConstraint) { _heightConstraint.Constant = MaxHeightConstraint; } // Prevent making the view too small if (_heightConstraint.Constant < MinimumHeight) { _heightConstraint.Constant = MinimumHeight; } // Enables 'flick' gesture to switch between states if (recognizer.State == UIGestureRecognizerState.Ended) { if (Math.Abs(recognizer.VelocityInView(View).Y) > 0) { HandleFlick(recognizer); } if (_heightConstraint.Constant == MinimumHeight && AllowsMinimizedState) { _currentState = BottomSheetState.Minimized; } else if (_heightConstraint.Constant == MaxHeightConstraint) { _currentState = BottomSheetState.Full; } else { _currentState = BottomSheetState.Partial; } } recognizer.SetTranslation(new CoreGraphics.CGPoint(0, 0), View); }
private void OnPanningGesture (UIPanGestureRecognizer gesture) { switch (gesture.State) { case UIGestureRecognizerState.Began: panStart = gesture.TranslationInView (actualContentView); panLockInHorizDirection = false; break; case UIGestureRecognizerState.Changed: var currentPoint = gesture.TranslationInView (actualContentView); panDeltaX = panStart.X - currentPoint.X; if (panDeltaX > 0) { panDeltaX = 0; return; } if (!panLockInHorizDirection) { if (Math.Abs (panDeltaX) > 30) { // User is swiping the cell, lock them into this direction panLockInHorizDirection = true; } else if (Math.Abs (panStart.Y - currentPoint.Y) > 5) { // User is starting to move upwards, let them scroll gesture.Enabled = false; } } if (-SwipeWidth > panDeltaX) { panDeltaX = -SwipeWidth; } UIView.AnimateNotify (0.1, 0, UIViewAnimationOptions.CurveEaseOut, LayoutActualContentView, null); break; case UIGestureRecognizerState.Ended: if (Editing) { break; } if (!gesture.Enabled) { gesture.Enabled = true; } var velocityX = gesture.VelocityInView (gesture.View).X; var absolutePanDeltaX = Math.Abs (panDeltaX); var duration = Math.Max (MinDuration, Math.Min (MaxDuration, (absolutePanDeltaX) / velocityX)); UIView.AnimateNotify (duration, () => LayoutActualContentView (0), isFinished => { if (isFinished && absolutePanDeltaX > SwipeWidth - 5) { OnContinueGestureFinished (); } }); break; case UIGestureRecognizerState.Cancelled: UIView.AnimateNotify (0.3, () => LayoutActualContentView (0), isFinished => gesture.Enabled = isFinished); break; } }
void OnMenuPan(UIPanGestureRecognizer panGestureRecognizer) { var translationX = panGestureRecognizer.TranslationInView(View).X; var menuView = menuViewController.View; switch (panGestureRecognizer.State) { case UIGestureRecognizerState.Began: { menuAnimator?.StopAnimation(true); } break; case UIGestureRecognizerState.Changed: { var potentialNewX = menuView.Frame.X + translationX; var translationFactor = GetMenuTranslationFactor(potentialNewX); var newX = menuView.Frame.X + (translationX * translationFactor); var totalXDistance = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin; var percentMaximized = (newX + UIScreen.MainScreen.Bounds.Width) / totalXDistance; menuView.Frame = new CGRect { Location = new CGPoint { X = newX, Y = menuView.Frame.Y, }, Size = menuView.Frame.Size, }; menuViewController.SetPercentMaximized((float)percentMaximized); menuBackgroundView.Alpha = percentMaximized; panGestureRecognizer.SetTranslation(CGPoint.Empty, View); } break; case UIGestureRecognizerState.Ended: { var x = menuView.Frame.X; var velocityX = panGestureRecognizer.VelocityInView(View).X; var totalXDistance = UIScreen.MainScreen.Bounds.Width - Constants.MenuRightMargin; var shouldMaximizeByLocation = (x + UIScreen.MainScreen.Bounds.Width) >= totalXDistance / 3f; var shouldMaximizeByVelocity = velocityX > Constants.PulloutVelocityThreshold; var shouldMinimizeByVelocity = -velocityX > Constants.PulloutVelocityThreshold; var shouldMaximize = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity); var DEST_X = shouldMaximize ? -Constants.MenuRightMargin : -UIScreen.MainScreen.Bounds.Width; var remainingDistance = Math.Abs(x - DEST_X); var initialVelocity = MenuIsExceedingBoundaries(menuView.Frame) ? 0f : (nfloat)Math.Abs(velocityX / remainingDistance); AnimateMenu(shouldMaximize ? MenuState.Open : MenuState.Closed, (float)initialVelocity); } break; } }
private void InfoPanGesture(UIPanGestureRecognizer recognizer) { if (_height < 0) { _height = _infoBlockView.Bounds.Height + IPHONE_X_OFFSET; } _maxInfoBlockTop = base.View.Bounds.Height - _height; var translation = recognizer.TranslationInView(_infoBlockView); var velocity = recognizer.VelocityInView(_infoBlockView); if (Math.Abs(velocity.X) > Math.Abs(velocity.Y)) { return; } var y = _infoBlockView.Frame.GetMinY(); if (recognizer.State == UIGestureRecognizerState.Changed) { if ((y + translation.Y >= _maxInfoBlockTop) && (y + translation.Y <= _minInfoBlockTop)) { _infoBlockView.Frame = new CGRect(0, y + translation.Y, _infoBlockView.Bounds.Width, _height); } else { _infoBlockView.Frame = new CGRect(0, (translation.Y >= 0) ? _minInfoBlockTop : _maxInfoBlockTop, _infoBlockView.Bounds.Width, _height); _titleLabel.Alpha = (translation.Y >= 0) ? 0 : 1; _addressLabel.Alpha = (translation.Y >= 0) ? 0 : 1; _distanceView.Alpha = (translation.Y >= 0) ? 0 : 1; _workTimeLabel.Alpha = (translation.Y >= 0) ? 0 : 1; _infoLabel.Alpha = (translation.Y >= 0) ? 0 : 1; } recognizer.SetTranslation(CGPoint.Empty, _infoBlockView); } else if (recognizer.State == UIGestureRecognizerState.Ended) { var duration = velocity.Y < 0 ? (y - _maxInfoBlockTop) / -velocity.Y : (_minInfoBlockTop - y) / velocity.Y; duration = duration > 1 ? (nfloat)0.8 : duration; UIView.Animate(duration, 0, UIViewAnimationOptions.AllowUserInteraction, () => { _infoBlockView.Frame = new CGRect(0, (velocity.Y >= 0) ? _minInfoBlockTop : _maxInfoBlockTop, _infoBlockView.Bounds.Width, _height); _titleLabel.Alpha = (velocity.Y >= 0) ? 0 : 1; _addressLabel.Alpha = (velocity.Y >= 0) ? 0 : 1; _distanceView.Alpha = (velocity.Y >= 0) ? 0 : 1; _workTimeLabel.Alpha = (velocity.Y >= 0) ? 0 : 1; _infoLabel.Alpha = (velocity.Y >= 0) ? 0 : 1; }, null); } }
void Pan(UIPanGestureRecognizer pan) { var location = pan.LocationInView(View); switch (pan.State) { case UIGestureRecognizerState.Began: // Capture the initial touch offset from the itemView's center. var center = itemView.Center; offset.X = location.X - center.X; offset.Y = location.Y - center.Y; // Disable the behavior while the item is manipulated by the pan recognizer. stickyBehavior.Enabled = false; break; case UIGestureRecognizerState.Changed: // Get reference bounds. var referenceBounds = View.Bounds; var referenceWidth = referenceBounds.Width; var referenceHeight = referenceBounds.Height; // Get item bounds. var itemBounds = itemView.Bounds; var itemHalfWidth = itemBounds.Width / 2f; var itemHalfHeight = itemBounds.Height / 2f; // Apply the initial offset. location.X -= offset.X; location.Y -= offset.Y; // Bound the item position inside the reference view. location.X = NMath.Max(itemHalfWidth, location.X); location.X = NMath.Min(referenceWidth - itemHalfWidth, location.X); location.Y = NMath.Max(itemHalfHeight, location.Y); location.Y = NMath.Min(referenceHeight - itemHalfHeight, location.Y); // Apply the resulting item center. itemView.Center = location; break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: // Get the current velocity of the item from the pan gesture recognizer. var velocity = pan.VelocityInView(View); // Re-enable the stickyCornersBehavior. stickyBehavior.Enabled = true; // Add the current velocity to the sticky corners behavior. stickyBehavior.AddLinearVelocity(velocity); break; } }
public void Null() { using (var pgr = new UIPanGestureRecognizer(Null)) { pgr.SetTranslation(CGPoint.Empty, null); var pt = pgr.TranslationInView(null); Assert.That(pt, Is.EqualTo(CGPoint.Empty), "TranslationInView"); pt = pgr.VelocityInView(null); Assert.That(pt, Is.EqualTo(CGPoint.Empty), "VelocityInView"); } }
public void DragContentView(UIPanGestureRecognizer panGesture) { //Console.WriteLine("drag flyout"); if (ShouldStayOpen || mainView == null) { return; } RectangleF frame = mainView.Frame; float translation = panGesture.TranslationInView(View).X; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.X = translation + startX; if (frame.X < 0) { frame.X = 0; } else if (frame.X > frame.Width) { frame.X = menuWidth; } SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { float velocity = panGesture.VelocityInView(View).X; //Console.WriteLine (velocity); float newX = translation + startX; Console.WriteLine(translation + startX); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startX <menuWidth ? (newX > (menuWidth / 2)) : newX> menuWidth; if (show) { ShowMenu(); } else { HideMenu(); } } }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen || mainView == null) return; if (!HideShadow) View.InsertSubviewBelow(shadowView, mainView); navigation.View.Hidden = false; RectangleF frame = mainView.Frame; shadowView.Frame = frame; float translation = panGesture.TranslationInView(View).X; if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.X = translation + startX; if (Position == FlyOutNavigationPosition.Left) { if (frame.X < 0) frame.X = 0; else if (frame.X > menuWidth) frame.X = menuWidth; } else { if (frame.X > 0) frame.X = 0; else if (frame.X < -menuWidth) frame.X = -menuWidth; } SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { float velocity = panGesture.VelocityInView(View).X; float newX = translation + startX; bool show = Math.Abs (velocity) > sidebarFlickVelocity ? velocity > 0 : newX > (menuWidth / 2); if (Position == FlyOutNavigationPosition.Right) { show = Math.Abs(velocity) > sidebarFlickVelocity ? velocity < 0 : newX < -(menuWidth / 2); } if (show) { ShowMenu (); } else { HideMenu (); } } }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen || mainView == null) { return; } var frame = mainView.Frame; var translation = panGesture.TranslationInView(View).Y; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startY = frame.Y; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.Y = translation + startY; if (frame.Y < 0) { frame.Y = 0; } else if (frame.Y > frame.Height) { frame.Y = menuHeight; } SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { var velocity = panGesture.VelocityInView(View).Y; //Console.WriteLine (velocity); var newY = translation + startY; Console.WriteLine(translation + startY); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startY <menuHeight ? (newY > (menuHeight / 2)) : newY> menuHeight; if (show) { ShowMenu(); } else { HideMenu(); } } }
private void HandlePan(UIPanGestureRecognizer recognizer) { var translation = recognizer.TranslationInView(this); Trace($"Pan translation: {translation.X}/{translation.Y}"); StopDeceleration(); switch (recognizer.State) { case UIGestureRecognizerState.Began: panGestureLastTranslation = recognizer.TranslationInView(this); ViewPort.Offset(panGestureLastTranslation); break; case UIGestureRecognizerState.Changed: var translationOffset = new CGPoint(panGestureLastTranslation.X - translation.X, panGestureLastTranslation.Y - translation.Y); ViewPort.Offset(translationOffset); Trace($"Pan translationOffset: {translationOffset.X}/{translationOffset.Y}"); panGestureLastTranslation = translation; break; case UIGestureRecognizerState.Ended: Trace($"Pan gesture ended"); var velocity = recognizer.VelocityInView(this); Trace($"Pan gesture velocity: {velocity.X}/{velocity.Y}"); InitDeceleration(velocity); break; default: break; } SetNeedsDisplay(); }
private void Panned(UIPanGestureRecognizer gestureRecognizer) { if (this.items.Count < 2 || this.contentWidth <= this.View.Bounds.Width) { return; } var panLocation = gestureRecognizer.TranslationInView(this.ContentView); var offset = this.currentScrolledOffset - panLocation.X; // this is the total amount that we've scrolled away from zero this.LayoutContent(this.LimitOffset(offset)); if (gestureRecognizer.State != UIGestureRecognizerState.Ended) { return; } var velocity = gestureRecognizer.VelocityInView(this.View).X; if (Math.Abs(velocity) < 500) { this.currentScrolledOffset = this.CalculatePannedLocation(offset, panLocation.X); this.ScrollContent(currentScrolledOffset); } else { if (panLocation.X < 0) { var proposedOffset = this.GetNextOffset(offset); this.currentScrolledOffset = proposedOffset; } else { var proposedOffset = this.GetPriorOffset(offset); this.currentScrolledOffset = proposedOffset; } this.ScrollContent(this.currentScrolledOffset); } gestureRecognizer.SetTranslation(PointF.Empty, this.View); }
/// <summary> /// Method that gets invoked when drag gesture is performed. /// </summary> /// <param name="dragGesture">Drag gesture.</param> public void DragBottomSheet(UIPanGestureRecognizer dragGesture) { var translation = dragGesture.TranslationInView(View); var velocity = dragGesture.VelocityInView(View); var bottomSheetY = View.Frame.GetMinY(); if (bottomSheetY + translation.Y <= m_PartialView && bottomSheetY + translation.Y >= m_FullView) { View.Frame = new CGRect(0, bottomSheetY + translation.Y, View.Frame.Width, View.Frame.Height); dragGesture.SetTranslation(m_CGPointZero, View); } if (dragGesture.State == UIGestureRecognizerState.Ended) { MoveSheetToBound(velocity.Y); } }
private void OnPan(UIPanGestureRecognizer pan, Shared.Calendar calendar) { if (pan.State == UIGestureRecognizerState.Began) { var screenWidth = UIScreen.MainScreen.Bounds.Width; var leftEdgeThreshold = screenWidth * 0.15f; var staringPoint = pan.LocationInView(null); if (staringPoint.X < leftEdgeThreshold) { _isSwipingFromLeftEdge = true; } } if (pan.State != UIGestureRecognizerState.Ended) { return; } var velocity = pan.VelocityInView(null); // going right var isSwipingRight = velocity.X > 0; // going left var isSwipingLeft = velocity.X < 0; if (_isSwipingFromLeftEdge) { PullOutMainMenu(); _isSwipingFromLeftEdge = false; return; } if (isSwipingRight && calendar != null) { SwipeFrame(calendar, true); } if (isSwipingLeft && calendar != null) { SwipeFrame(calendar, false); } }
private void PanHandler(UIPanGestureRecognizer gesture) { CGPoint translation = gesture.TranslationInView(rotationView); if (gesture.State == UIGestureRecognizerState.Began) { tile.Frame = tile.Layer.PresentationLayer.Frame; tile.Layer.RemoveAllAnimations(); } else if (gesture.State == UIGestureRecognizerState.Changed) { Stopwatch sw = Stopwatch.StartNew(); var offsetX = translation.X; var offsetY = translation.Y; var newLeft = tile.Frame.GetMinX() + offsetX; var newTop = tile.Frame.GetMinY() + offsetY; tile.Frame = new CGRect(newLeft, newTop, tile.Frame.Width, tile.Frame.Height); gesture.SetTranslation(new CGPoint(0, 0), View); sw.Stop(); Console.WriteLine("Panning: " + sw.ElapsedMilliseconds); } else if (gesture.State == UIGestureRecognizerState.Ended) { Stopwatch sw = Stopwatch.StartNew(); var inertia = gesture.VelocityInView(rotationView); var offsetX = inertia.X * animationOffsetRatio; var offsetY = inertia.Y * animationOffsetRatio; var newLeft = tile.Frame.X + offsetX; var newTop = tile.Frame.Y + offsetY; UIView.Animate(animationDuration, 0, UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.AllowUserInteraction, () => { tile.Frame = new CGRect(newLeft, newTop, tile.Frame.Width, tile.Frame.Height); }, () => { sw.Stop(); Console.WriteLine("Paned: " + sw.ElapsedMilliseconds); }); } }
public void HandelePanGesture(UIPanGestureRecognizer gesture) { switch (gesture.State) { case UIGestureRecognizerState.Began: _topInset = _navBarController.View.Frame.Size.Height + _extensionController.View.Bounds.Height + StatusBarHeight(); break; case UIGestureRecognizerState.Changed: HandleScrolling(); break; default: var velocity = gesture.VelocityInView(_scrollView).Y; HandleScrollingEnded(velocity); break; } }
public void iOSPanGesture(UIPanGestureRecognizer obj) { Rock.Mobile.Util.Debug.WriteLine("Panning"); // get the required data from the gesture and call our base function CGPoint currVelocity = obj.VelocityInView((UIView)ParentView); CGPoint deltaPan = new CGPoint(0, 0); PlatformCardCarousel.PanGestureState state = PlatformCardCarousel.PanGestureState.Began; switch (obj.State) { case UIGestureRecognizerState.Began: { PanLastPos = new PointF(0, 0); CommitCardPositions( ); state = PlatformCardCarousel.PanGestureState.Began; break; } case UIGestureRecognizerState.Changed: { CGPoint absolutePan = obj.TranslationInView((UIView)ParentView); deltaPan = new CGPoint(absolutePan.X - PanLastPos.X, 0); PanLastPos = absolutePan; state = PlatformCardCarousel.PanGestureState.Changed; break; } case UIGestureRecognizerState.Ended: { UpdateCardPositions( ); state = PlatformCardCarousel.PanGestureState.Ended; break; } } base.OnPanGesture(state, currVelocity.ToPointF( ), deltaPan.ToPointF( )); }
private void OnPanned(UIPanGestureRecognizer panRecognizer) { CGPoint translation = panRecognizer.TranslationInView(View); CGPoint velocity = panRecognizer.VelocityInView(View); if (panRecognizer.State == UIGestureRecognizerState.Began) { _panVertical = (Math.Abs(velocity.Y) > Math.Abs(velocity.X)); if (_panVertical) { _panStartValue = _shimmeringView.ShimmeringSpeed; } else { _panStartValue = _shimmeringView.ShimmeringOpacity; } AnimateValueLabelVisible(true); } else if (panRecognizer.State == UIGestureRecognizerState.Changed) { nfloat directional = (_panVertical ? translation.Y : translation.X); nfloat possible = (_panVertical ? View.Bounds.Size.Height : View.Bounds.Size.Width); nfloat progress = (directional / possible); if (_panVertical) { _shimmeringView.ShimmeringSpeed = (nfloat)Math.Max(0.0f, Math.Min(1000.0f, _panStartValue + progress * 200.0f)); _valueLabel.Text = string.Format("Speed\n{0:0.0}", _shimmeringView.ShimmeringSpeed); } else { _shimmeringView.ShimmeringOpacity = (nfloat)Math.Max(0.0f, Math.Min(1.0f, _panStartValue + progress * 0.5f)); _valueLabel.Text = string.Format("Opacity\n{0:0.00}", _shimmeringView.ShimmeringOpacity); } } else if (panRecognizer.State == UIGestureRecognizerState.Ended || panRecognizer.State == UIGestureRecognizerState.Cancelled) { AnimateValueLabelVisible(false); } }
void Panned(UIPanGestureRecognizer panGesture) { CGRect frame = NowPlaying.View.Frame; nfloat translation = panGesture.TranslationInView(this).Y; //Console.WriteLine("Translation: {0}, {1}", translation, NowPlaying.GetOffset()); if (panGesture.State == UIGestureRecognizerState.Began) { isPanning = true; startY = frame.Y; //NowPlaying.BackgroundView = Menu.View; //NowPlaying.UpdateBackgound(); } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.Y = translation + startY; frame.Y = NMath.Min(frame.Height, NMath.Max(frame.Y, NowPlaying.GetHeaderOverhangHeight() * -1)); NowPlaying.View.Frame = frame; } else if (panGesture.State == UIGestureRecognizerState.Ended) { isPanning = false; var velocity = panGesture.VelocityInView(this).Y; // Console.WriteLine (velocity); var show = (Math.Abs(velocity) > FlickVelocity) ? (velocity < 0) : (translation * -1 > NowPlayingGestureTollerance); const float playbackBarHideTollerance = NowPlayingViewController.PlaybackBarHeight * 2 / 3; if (show) { ShowNowPlaying(true); } else { HideNowPlaying(true, Math.Abs(velocity) > FlickVelocity || (translation > 5 && NowPlaying.GetOffset() - NowPlaying.GetHeaderOverhangHeight() < playbackBarHideTollerance)); } } }
public void HandleHideMenuPan(UIPanGestureRecognizer pan) { var translation = pan.TranslationInView(pan.View); var direction = this.PresentDirection == UIRectEdge.Left ? -1 : 1; var distance = translation.X / SideMenuManager.MenuWidth * direction; switch (pan.State) { case UIGestureRecognizerState.Began: interactive = true; viewControllerForPresentedMenu?.DismissViewController(true, null); break; case UIGestureRecognizerState.Changed: this.UpdateInteractiveTransition((float)Math.Max(Math.Min(distance, 1), 0)); break; default: interactive = false; var velocity = pan.VelocityInView(pan.View).X *direction; if (velocity >= 100 || velocity >= -50 && 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 > 1 - 1.192092896e-07F) //{ // this.UpdateInteractiveTransition(0.9999); //} this.FinishInteractiveTransition(); } else { this.CancelInteractiveTransition(); } break; } }
public NodeTouchEvent(NodeUIView parent, UIPanGestureRecognizer pan) { switch (pan.State) { case UIGestureRecognizerState.Began: type = TouchType.Down; break; case UIGestureRecognizerState.Changed: type = TouchType.Move; break; case UIGestureRecognizerState.Ended: type = TouchType.Up; break; case UIGestureRecognizerState.Possible: case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: break; } var p = pan.LocationInView (parent); point = new Point (p.X, p.Y); var velo = pan.VelocityInView (parent); velocity = new Vec2 (velo.X / 1000, velo.Y / 1000); }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen || mainView == null) return; if (!HideShadow) View.InsertSubviewBelow(shadowView, mainView); navigation.View.Hidden = false; RectangleF frame = mainView.Frame; shadowView.Frame = frame; float translation = panGesture.TranslationInView(View).X; if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.X = translation + startX; if (Position == FlyOutNavigationPosition.Left) { if (frame.X < 0) frame.X = 0; else if (frame.X > menuWidth) frame.X = menuWidth; } else { if (frame.X > 0) frame.X = 0; else if (frame.X < -menuWidth) frame.X = -menuWidth; } SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { float velocity = panGesture.VelocityInView(View).X; float newX = translation + startX; bool show = Math.Abs (velocity) > sidebarFlickVelocity ? velocity > 0 : newX > (menuWidth / 2); if (Position == FlyOutNavigationPosition.Right) { show = Math.Abs(velocity) > sidebarFlickVelocity ? velocity < 0 : newX < -(menuWidth / 2); } if (show) { ShowMenu (); } else { HideMenu (); } } }
void Pan (UIPanGestureRecognizer pan) { var location = pan.LocationInView (View); switch (pan.State) { case UIGestureRecognizerState.Began: // Capture the initial touch offset from the itemView's center. var center = itemView.Center; offset.X = location.X - center.X; offset.Y = location.Y - center.Y; // Disable the behavior while the item is manipulated by the pan recognizer. stickyBehavior.Enabled = false; break; case UIGestureRecognizerState.Changed: // Get reference bounds. var referenceBounds = View.Bounds; var referenceWidth = referenceBounds.Width; var referenceHeight = referenceBounds.Height; // Get item bounds. var itemBounds = itemView.Bounds; var itemHalfWidth = itemBounds.Width / 2f; var itemHalfHeight = itemBounds.Height / 2f; // Apply the initial offset. location.X -= offset.X; location.Y -= offset.Y; // Bound the item position inside the reference view. location.X = NMath.Max (itemHalfWidth, location.X); location.X = NMath.Min (referenceWidth - itemHalfWidth, location.X); location.Y = NMath.Max (itemHalfHeight, location.Y); location.Y = NMath.Min (referenceHeight - itemHalfHeight, location.Y); // Apply the resulting item center. itemView.Center = location; break; case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: // Get the current velocity of the item from the pan gesture recognizer. var velocity = pan.VelocityInView (View); // Re-enable the stickyCornersBehavior. stickyBehavior.Enabled = true; // Add the current velocity to the sticky corners behavior. stickyBehavior.AddLinearVelocity (velocity); break; } }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen) return; var translation = panGesture.TranslationInView (View).X; var frame = mainView.Bounds; if (panGesture.State == UIGestureRecognizerState.Changed) { if (IsOpen) { if (translation > 0.0f) { ShowMenu(); } else if (translation < - menuWidth) { HideMenu(); } else { frame.X = menuWidth + translation; SetLocation(frame); } } else { if (translation < 0.0f) { HideMenu(); } else if (translation > menuWidth) { ShowMenu(); } else { frame.X = translation; SetLocation(frame); } } } else if (panGesture.State == UIGestureRecognizerState.Ended) { var velocity = panGesture.VelocityInView(View).X; bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : (translation > (menuWidth / 2)); if(show) ShowMenu(); else HideMenu(); } }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen || mainView == null) return; RectangleF frame = mainView.Frame; float translation = panGesture.TranslationInView(View).X; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.X = translation + startX; if (frame.X < 0) frame.X = 0; else if (frame.X > frame.Width) frame.X = menuWidth; SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { float velocity = panGesture.VelocityInView(View).X; //Console.WriteLine (velocity); float newX = translation + startX; Console.WriteLine(translation + startX); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startX < menuWidth ? (newX > (menuWidth/2)) : newX > menuWidth; if (show) ShowMenu(); else HideMenu(); } }
private void OnPanned(UIPanGestureRecognizer panRecognizer) { PointF translation = panRecognizer.TranslationInView(View); PointF velocity = panRecognizer.VelocityInView(View); if (panRecognizer.State == UIGestureRecognizerState.Began) { _panVertical = (Math.Abs(velocity.Y) > Math.Abs(velocity.X)); if (_panVertical) { _panStartValue = _shimmeringView.ShimmeringSpeed; } else { _panStartValue = _shimmeringView.ShimmeringOpacity; } AnimateValueLabelVisible(true); } else if (panRecognizer.State == UIGestureRecognizerState.Changed) { float directional = (_panVertical ? translation.Y : translation.X); float possible = (_panVertical ? View.Bounds.Size.Height : View.Bounds.Size.Width); float progress = (directional / possible); if (_panVertical) { _shimmeringView.ShimmeringSpeed = (float)Math.Max(0.0f, Math.Min(1000.0f, _panStartValue + progress * 200.0f)); _valueLabel.Text = string.Format("Speed\n{0:0.0}", _shimmeringView.ShimmeringSpeed); } else { _shimmeringView.ShimmeringOpacity = (float)Math.Max(0.0f, Math.Min(1.0f, _panStartValue + progress * 0.5f)); _valueLabel.Text = string.Format("Opacity\n{0:0.00}", _shimmeringView.ShimmeringOpacity); } } else if (panRecognizer.State == UIGestureRecognizerState.Ended || panRecognizer.State == UIGestureRecognizerState.Cancelled) { AnimateValueLabelVisible(false); } }
private void Panned(UIPanGestureRecognizer gestureRecognizer) { if (this.items.Count < 2 || this.contentWidth <= this.View.Bounds.Width) { return; } // quick hack for nested panoramas if (this.presentedController is UIPanoramaViewController) { return; } var panLocation = gestureRecognizer.TranslationInView(this.ContentView); var offset = this.currentScrolledOffset - panLocation.X; // this is the total amount that we've scrolled away from zero this.LayoutContent(this.LimitOffset(offset)); if (gestureRecognizer.State != UIGestureRecognizerState.Ended) { return; } var velocity = gestureRecognizer.VelocityInView(this.View).X; if (Math.Abs(velocity) < 700) { this.currentScrolledOffset = this.CalculatePannedLocation(offset, panLocation.X); this.ScrollContent(currentScrolledOffset); } else { if (panLocation.X < 0) { var proposedOffset = this.GetNextOffset(offset); this.currentScrolledOffset = proposedOffset; } else { var proposedOffset = this.GetPriorOffset(offset); this.currentScrolledOffset = proposedOffset; } this.ScrollContent(this.currentScrolledOffset); } gestureRecognizer.SetTranslation(PointF.Empty, this.View); }
private void dismissingPanGestureRecognizerPanned(UIPanGestureRecognizer panner) { if (Flags.ScrollViewIsAnimatingAZoom || Flags.IsAnimatingAPresentationOrDismissal) return; PointF translation = panner.TranslationInView (panner.View); PointF locationInView = panner.LocationInView (panner.View); PointF velocity = panner.VelocityInView (panner.View); float vectorDistance = (float)Math.Sqrt (Math.Pow (velocity.X, 2) + Math.Pow (velocity.Y, 2)); if (panner.State == UIGestureRecognizerState.Began) { Flags.IsDraggingImage = ImageView.Frame.Contains (locationInView); if (Flags.IsDraggingImage) StartImageDragging (locationInView, new UIOffset ()); } else if (panner.State == UIGestureRecognizerState.Changed) { if (Flags.IsDraggingImage) { PointF newAnchor = ImageDragStartingPoint; newAnchor.X += translation.X + ImageDragOffsetFromActualTranslation.Horizontal; newAnchor.Y += translation.Y + ImageDragOffsetFromActualTranslation.Vertical; AttachmentBehavior.AnchorPoint = newAnchor; } else { Flags.IsDraggingImage = ImageView.Frame.Contains (locationInView); if (Flags.IsDraggingImage) { UIOffset translationOffset = new UIOffset (-1 * translation.X, -1 * translation.Y); StartImageDragging (locationInView, translationOffset); } } } else { if (vectorDistance > JTSImageViewController.JTSImageViewController_MinimumFlickDismissalVelocity) { if (Flags.IsDraggingImage) { DismissImageWithFlick (velocity); } else { Dismiss (true); } } else { CancelCurrentImageDrag (true); } } }
private void HandlePan(UIPanGestureRecognizer rec) { if (rec.State == UIGestureRecognizerState.Began) { HandleTouchesBeganAtLocation(rec.LocationInView(View)); } else if (rec.State == UIGestureRecognizerState.Changed) { HandleTouchesMovedToLocation(rec.LocationInView(View)); } else if (rec.State == UIGestureRecognizerState.Ended || rec.State == UIGestureRecognizerState.Cancelled || rec.State == UIGestureRecognizerState.Failed) { float velocity = rec.VelocityInView(View).X; if (Math.Abs(velocity) > kLWMinimumVelocityToTriggerSlide) { if (velocity > 0f) { SlideOutSlideNavigationView(); } else { SlideInSlideNavigationView(); } } else { HandleTouchesEndedAtLocation(rec.LocationInView(View)); } } }
void HandlePulloutPan(UIPanGestureRecognizer panGestureRecognizer) { var translationY = panGestureRecognizer.TranslationInView(View).Y; switch (panGestureRecognizer.State) { case UIGestureRecognizerState.Began: { pulloutAnimator?.StopAnimation(true); mainPulloutView.PulloutBeganDragging(pulloutState); } break; case UIGestureRecognizerState.Changed: { var potentialNewY = mainPulloutView.Frame.Y + translationY; var translationFactor = GetTranslationFactor(potentialNewY); var newY = mainPulloutView.Frame.Y + (translationY * translationFactor); var totalYDistance = (UIScreen.MainScreen.Bounds.Height - Constants.PulloutBottomMargin) - Constants.PulloutTopMargin; var percentMaximized = 1 - ((newY - Constants.PulloutTopMargin) / totalYDistance); mainPulloutView.Frame = new CGRect { Location = new CGPoint { X = mainPulloutView.Frame.X, Y = newY, }, Size = mainPulloutView.Frame.Size, }; mainPulloutView.SetPercentMaximized(percentMaximized); pulloutBackgroundView.Alpha = percentMaximized; var minimizedTotalDistance = pulloutMinDestY - pulloutNeutralDestY; var minimizedDeltaProgress = newY - pulloutNeutralDestY; minimizedDeltaProgress = minimizedDeltaProgress < 0 ? 0 : minimizedDeltaProgress; var percentMinimized = minimizedDeltaProgress / minimizedTotalDistance; percentMinimized = percentMinimized > 1 ? 1 : (percentMinimized < 0 ? 0 : percentMinimized); mainPulloutView.SetPercentMinimized(percentMinimized); panGestureRecognizer.SetTranslation(CGPoint.Empty, View); } break; case UIGestureRecognizerState.Ended: { var y = mainPulloutView.Frame.Y; var velocityY = panGestureRecognizer.VelocityInView(View).Y; var shouldMaximizeByLocation = y <= pulloutMaxDestY || Math.Abs(y - pulloutMaxDestY) < (pulloutNeutralDestY - pulloutMaxDestY) / 2; var shouldMaximizeByVelocity = -velocityY > Constants.PulloutVelocityThreshold; var shouldMinimizeByVelocity = velocityY > Constants.PulloutVelocityThreshold; var shouldMaximize = !shouldMinimizeByVelocity && (shouldMaximizeByLocation || shouldMaximizeByVelocity); var newPulloutState = shouldMaximize ? PulloutState.Maximized : (isPulloutInMinMode ? PulloutState.Minimized : PulloutState.Neutral); var DEST_Y = PulloutDestinationYFromState(newPulloutState); var remainingDistance = Math.Abs(y - DEST_Y); AnimatePullout(newPulloutState, (float)(PulloutIsExceedingBoundaries(mainPulloutView.Frame) ? 0f : (nfloat)Math.Abs(velocityY / remainingDistance))); } break; } }
/// <summary> /// Pans the gesture recognized. /// </summary> /// <param name="recognizer">Recognizer.</param> public void PanGestureRecognized(UIPanGestureRecognizer recognizer) { if (this.FrostedViewController.Delegate != null) { this.FrostedViewController.Delegate.DidRecognizePanGesture(this.FrostedViewController, recognizer); } if (!this.FrostedViewController.PanGestureEnabled) { return; } var point = recognizer.TranslationInView(this.View); if (recognizer.State == UIGestureRecognizerState.Began) { this.ContainerOrigin = this.ContainerView.Frame.Location; } if (recognizer.State == UIGestureRecognizerState.Changed) { var frame = this.ContainerView.Frame; if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Left) { frame.X = this.ContainerOrigin.X + point.X; if (frame.Location.X > 0) { frame.X = 0; if (!this.FrostedViewController.LimitMenuViewSize) { frame.Width = this.FrostedViewController.CalculatedMenuViewSize.Width + this.ContainerOrigin.X + point.X; if (frame.Size.Width > this.View.Frame.Size.Width) { frame.Width = this.View.Frame.Size.Width; } } } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Right) { frame.X = this.ContainerOrigin.X + point.X; if (frame.Location.X < this.View.Frame.Size.Width - this.FrostedViewController.CalculatedMenuViewSize.Width) { frame.X = this.View.Frame.Size.Width - this.FrostedViewController.CalculatedMenuViewSize.Width; if (!this.FrostedViewController.LimitMenuViewSize) { frame.X = this.ContainerOrigin.X + point.X; if (frame.Location.X < 0) { frame.X = 0; } frame.Width = this.View.Frame.Size.Width - frame.Location.X; } } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Top) { frame.Y = this.ContainerOrigin.Y + point.Y; if (frame.Location.Y > 0) { frame.Y = 0; if (!this.FrostedViewController.LimitMenuViewSize) { frame.Height = this.FrostedViewController.CalculatedMenuViewSize.Height + this.ContainerOrigin.Y + point.Y; if (frame.Size.Height > this.View.Frame.Size.Height) { frame.Height = this.View.Frame.Size.Height; } } } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Bottom) { frame.Y = this.ContainerOrigin.Y + point.Y; if (frame.Location.Y < this.View.Frame.Size.Height - this.FrostedViewController.CalculatedMenuViewSize.Height) { frame.Y = this.View.Frame.Size.Height - this.FrostedViewController.CalculatedMenuViewSize.Height; if (!this.FrostedViewController.LimitMenuViewSize) { frame.Y = this.ContainerOrigin.Y + point.Y; if (frame.Location.Y < 0) { frame.Y = 0; } frame.Height = this.View.Frame.Size.Height - frame.Location.Y; } } } SetContainerFrame(frame); } if (recognizer.State == UIGestureRecognizerState.Ended) { if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Left) { if (recognizer.VelocityInView(this.View).X < 0) { Hide(); } else { Show(); } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Right) { if (recognizer.VelocityInView(this.View).X < 0) { Show(); } else { Hide(); } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Top) { if (recognizer.VelocityInView(this.View).Y < 0) { Hide(); } else { Show(); } } if (this.FrostedViewController.Direction == REFrostedViewControllerDirection.Bottom) { if (recognizer.VelocityInView(this.View).Y < 0) { Show(); } else { Hide(); } } } }
void PanGestureRecognized(UIPanGestureRecognizer recognizer) { // if ([self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:didRecognizePanGesture:)]) // [self.delegate sideMenu:self didRecognizePanGesture:recognizer]; if (!_panGestureEnabled) { return; } PointF point = recognizer.TranslationInView(View); if (recognizer.State == UIGestureRecognizerState.Began) { UpdateContentViewShadow(); _originalPoint = new PointF((float)(_contentViewContainer.Center.X - _contentViewContainer.Bounds.Width / 2.0), (float)(_contentViewContainer.Center.Y - _contentViewContainer.Bounds.Height / 2.0)); _menuViewContainer.Transform = CGAffineTransform.MakeIdentity(); if (_scaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeIdentity(); _backgroundImageView.Frame = View.Bounds; } _menuViewContainer.Frame = View.Bounds; AddContentButton(); View.Window.EndEditing(true); _didNotifyDelegate = false; } if (recognizer.State == UIGestureRecognizerState.Changed) { float delta = 0; if (Visible) { delta = _originalPoint.X != 0 ? (point.X + _originalPoint.X) / _originalPoint.X : 0; } else { delta = point.X / View.Frame.Size.Width; } delta = Math.Min(Math.Abs(delta), 1.6F); float contentViewScale = _scaleContentView ? 1 - ((1 - _contentViewScaleValue) * delta) : 1; float backgroundViewScale = 1.7f - (0.7f * delta); float menuViewScale = 1.5f - (0.5f * delta); if (!_bouncesHorizontally) { contentViewScale = Math.Max(contentViewScale, _contentViewScaleValue); backgroundViewScale = Math.Max(backgroundViewScale, 1.0F); menuViewScale = Math.Max(menuViewScale, 1.0F); } _menuViewContainer.Alpha = delta; if (_scaleBackgroundImageView) { _backgroundImageView.Transform = CGAffineTransform.MakeScale(backgroundViewScale, backgroundViewScale); } if (_scaleMenuView) { _menuViewContainer.Transform = CGAffineTransform.MakeScale(menuViewScale, menuViewScale); } if (_scaleBackgroundImageView) { if (backgroundViewScale < 1) { _backgroundImageView.Transform = CGAffineTransform.MakeIdentity(); } } if (!_bouncesHorizontally && Visible) { if (_contentViewContainer.Frame.Location.X > _contentViewContainer.Frame.Size.Width / 2.0) point.X = Math.Min(0.0F, point.X); if (_contentViewContainer.Frame.Location.X < -(_contentViewContainer.Frame.Size.Width / 2.0)) point.X = Math.Max(0.0F, point.X); } // Limit size // if (point.X < 0) { point.X = Math.Max(point.X, - UIScreen.MainScreen.Bounds.Size.Height); } else { point.X = Math.Min(point.X, UIScreen.MainScreen.Bounds.Size.Height); } recognizer.SetTranslation (point, View); if (!_didNotifyDelegate) { if (point.X > 0) { // if (!Visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) { // [self.delegate sideMenu:self willShowMenuViewController:self.leftMenuViewController]; // } } if (point.X < 0) { // if (!self.visible && [self.delegate conformsToProtocol:@protocol(RESideMenuDelegate)] && [self.delegate respondsToSelector:@selector(sideMenu:willShowMenuViewController:)]) { // //[self.delegate sideMenu:self willShowMenuViewController:self.rightMenuViewController]; // } } _didNotifyDelegate = true; } if (contentViewScale > 1) { float oppositeScale = (1 - (contentViewScale - 1)); _contentViewContainer.Transform = CGAffineTransform.MakeScale(oppositeScale, oppositeScale); _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0); } else { _contentViewContainer.Transform = CGAffineTransform.MakeScale(contentViewScale, contentViewScale); _contentViewContainer.Transform = CGAffineTransform.Translate(_contentViewContainer.Transform, point.X, 0); } if (_leftMenuViewController != null) _leftMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X < 0; if (_rightMenuViewController != null) _rightMenuViewController.View.Hidden = _contentViewContainer.Frame.Location.X > 0; if (_leftMenuViewController == null && _contentViewContainer.Frame.Location.X > 0) { _contentViewContainer.Transform = CGAffineTransform.MakeIdentity(); _contentViewContainer.Frame = View.Bounds; Visible = false; _leftMenuVisible = false; } else if (_rightMenuViewController == null && _contentViewContainer.Frame.Location.X < 0) { _contentViewContainer.Transform = CGAffineTransform.MakeIdentity(); _contentViewContainer.Frame = View.Bounds; Visible = false; _rightMenuVisible = false; } StatusBarNeedsAppearanceUpdate (); } if (recognizer.State == UIGestureRecognizerState.Ended) { _didNotifyDelegate = false; if (_leftMenuViewController != null) _leftMenuViewController.View.Hidden = false; if (_rightMenuViewController != null) _rightMenuViewController.View.Hidden = false; if (_panMinimumOpenThreshold > 0 && ( (_contentViewContainer.Frame.Location.X < 0 && _contentViewContainer.Frame.Location.X > -((int)_panMinimumOpenThreshold)) || (_contentViewContainer.Frame.Location.X > 0 && _contentViewContainer.Frame.Location.X < _panMinimumOpenThreshold)) ) { HideMenuViewController (this, null); } else if (_contentViewContainer.Frame.Location.X == 0) { HideMenuViewControllerAnimated(false); } else { if (recognizer.VelocityInView(View).X > 0) { if (_contentViewContainer.Frame.Location.X < 0) { HideMenuViewController (this, null); } else { if (_leftMenuViewController != null) { ShowLeftMenuViewController (); } } } else { if (_contentViewContainer.Frame.Location.X < 20) { if (_rightMenuViewController != null) { ShowRightMenuViewController (); } } else { HideMenuViewController (this, null); } } } } }
public void DragContentView (UIPanGestureRecognizer panGesture) { float translation = (float) panGesture.TranslationInView (View).X; if (panGesture.State == UIGestureRecognizerState.Changed) { if (SidebarShowing) { if (translation > 0.0f) { _contentView.Frame = _contentView.Bounds #if __UNIFIED__ #else .OffsetNew (kGHRevealSidebarWidth, 0.0f) #endif ; SidebarShowing = true; } else if (translation < -kGHRevealSidebarWidth) { _contentView.Frame = _contentView.Bounds; SidebarShowing = false; } else { _contentView.Frame = _contentView.Bounds #if __UNIFIED__ #else .OffsetNew ((kGHRevealSidebarWidth + translation), 0.0f) #endif ; } } else { if (translation < 0.0f) { _contentView.Frame = _contentView.Bounds; #if __UNIFIED__ #else SidebarShowing = false #endif ; } else if (translation > kGHRevealSidebarWidth) { _contentView.Frame = _contentView.Bounds #if __UNIFIED__ #else .OffsetNew (kGHRevealSidebarWidth, 0.0f) #endif ; SidebarShowing = true; } else { _contentView.Frame = _contentView.Bounds #if __UNIFIED__ #else .OffsetNew (translation, 0.0f) #endif ; } } } else if (panGesture.State == UIGestureRecognizerState.Ended) { float velocity = (float) panGesture.VelocityInView (View).X; bool show = (Math.Abs (velocity) > kGHRevealSidebarFlickVelocity) ? (velocity > 0) : (translation > (kGHRevealSidebarWidth / 2)); ToggleSidebar (show, kGHRevealSidebarDefaultAnimationDuration); } }
void HandleDrag(UIPanGestureRecognizer sender) { switch (sender.State) { case UIGestureRecognizerState.Began: startPos = this.Center; // Determines if the view can be pulled in the x or y axis verticalAxis = closedCenter.X == openedCenter.X; // Finds the minimum and maximum points in the axis if (verticalAxis) { minPos = closedCenter.Y < openedCenter.Y ? closedCenter : openedCenter; maxPos = closedCenter.Y > openedCenter.Y ? closedCenter : openedCenter; } else { minPos = closedCenter.X < openedCenter.X ? closedCenter : openedCenter; maxPos = closedCenter.X > openedCenter.X ? closedCenter : openedCenter; } break; case UIGestureRecognizerState.Changed: PointF translate = sender.TranslationInView(this.Superview); PointF newPos; // Moves the view, keeping it constrained between openedCenter and closedCenter if (verticalAxis) { newPos = new PointF(startPos.X, startPos.Y + translate.Y); if (newPos.Y < minPos.Y) { newPos.Y = minPos.Y; translate = new PointF(0, newPos.Y - startPos.Y); } if (newPos.Y > maxPos.Y) { newPos.Y = maxPos.Y; translate = new PointF(0, newPos.Y - startPos.Y); } } else { newPos = new PointF(startPos.X + translate.X, startPos.Y); if (newPos.X < minPos.X) { newPos.X = minPos.X; translate = new PointF(newPos.X - startPos.X, 0); } if (newPos.X > maxPos.X) { newPos.X = maxPos.X; translate = new PointF(newPos.X - startPos.X, 0); } } sender.SetTranslation(translate, this.Superview); this.Center = newPos; break; case UIGestureRecognizerState.Ended: PointF vectorVelocity = sender.VelocityInView(this.Superview); float axisVelocity = verticalAxis ? vectorVelocity.Y : vectorVelocity.X; PointF target = axisVelocity < 0 ? minPos : maxPos; bool op = target == openedCenter ? true : false; this.SetOpenedAnimated(op, animate); break; } }
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; } }
protected void HandlePan(UIPanGestureRecognizer gesture) { // Prepare values UIView topView = this.TopViewController.View; float translationX = gesture.TranslationInView (this.View).X; float velocityX = gesture.VelocityInView(this.View).X; // Handle gesture switch (gesture.State) { case UIGestureRecognizerState.Began: { this.SlidingTransition.PanBegan(this, topView, translationX, velocityX); break; } case UIGestureRecognizerState.Changed: { this.SlidingTransition.PanChanged(this, topView, translationX, velocityX); break; } case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: { this.SlidingTransition.PanEnded(this, topView, translationX, velocityX); break; } } }
private void Panned(UIPanGestureRecognizer panner) { if (!this.Enabled) return; nfloat px = this.SlidingControllerView.Frame.Location.X; nfloat x = this.LocationOfPanner(panner); nfloat w = this.ReferenceBounds.Size.Width; Action didCloseSelector = null; Action didOpenSelector = null; // if we move over a boundary while dragging, ... if (px <= 0 && x >= 0 && px != x) { // ... then we need to check if the other side can open. if (px < 0) { bool canClose = true; if (this.Delegate != null) { canClose = this.Delegate.WillCloseRightView(this, false); didCloseSelector = () => this.Delegate.DidCloseRightView(this, false); } if (!canClose) { return; } } if (x > 0) { bool canOpen = true; if (this.Delegate != null) { canOpen = this.Delegate.WillOpenLeftView(this, false); didOpenSelector = () => this.Delegate.DidOpenLeftView(this, false); } if (!canOpen) { this.CloseRightView(false); return; } } } else if (px >= 0 && x <= 0 && px != x) { if (px > 0) { bool canClose = true; if (this.Delegate != null) { canClose = this.Delegate.WillCloseLeftView(this, false); didCloseSelector = () => this.Delegate.DidCloseLeftView(this, false); } if (!canClose) { return; } } if (x < 0) { bool canOpen = true; if (this.Delegate != null) { canOpen = this.Delegate.WillOpenRightView(this, false); didOpenSelector = () => this.Delegate.DidOpenRightView(this, false); } if (!canOpen) { this.CloseLeftView(false); return; } } } this.SetSlidingFrameForOffset(x); if (this.Delegate != null) { this.Delegate.DidPanToOffset(this, x); } if (panner.State == UIGestureRecognizerState.Ended) { if (this.SlidingControllerView.Frame.Location.X == 0.0f) { this.CenterViewVisible(); } else { this.CenterViewHidden(); } nfloat lw3 = (w - this.LeftLedge) / 3.0f; nfloat rw3 = (w - this.RightLedge) / 3.0f; nfloat velocity = panner.VelocityInView(this.referenceView).X; if (Math.Abs(velocity) < 500) { // small velocity, no movement if (x >= w - this.LeftLedge - lw3) { this.OpenLeftView(true, UIViewAnimationOptions.CurveEaseOut, false, null); } else if (x <= this.RightLedge + rw3 - w) { this.OpenRightView(true, UIViewAnimationOptions.CurveEaseOut, false, null); } else { this.ShowCenterView(true); } } else if (velocity < 0) { // swipe to the left if (x < 0) { this.OpenRightView(true, UIViewAnimationOptions.CurveEaseOut, true, null); } else { this.ShowCenterView(true); } } else if (velocity > 0) { // swipe to the right if (x > 0) { this.OpenLeftView(true, UIViewAnimationOptions.CurveEaseOut, true, null); } else { this.ShowCenterView(true); } } } else { this.HideAppropriateSideViews(); } if (didCloseSelector != null) { didCloseSelector(); } if (didOpenSelector != null) { didOpenSelector(); } }
void FinishPan(UIPanGestureRecognizer panGestureRecognizer, nfloat verticalDelta, UIView viewToPan, CGPoint anchorPoint) { var fromView = _transitionContext?.GetViewFor(UITransitionContext.FromViewKey); var velocityY = panGestureRecognizer.VelocityInView(panGestureRecognizer.View).Y; var animationDuration = Math.Abs(velocityY) * PhotoDismissalInteractionControllerReturnToCenterVelocityAnimationRatio + 0.2; var animationCurve = UIViewAnimationOptions.CurveEaseOut; var finalPageViewCenterPount = anchorPoint; var finalBackgroundAlpha = 1.0f; var dismissDistance = (fromView == null) ? 0.0f : PhotoDismissalInteractionControllerPanDismissDistanceRatio * fromView.Bounds.Height; var isDismissing = Math.Abs(verticalDelta) > dismissDistance; var didAnimateUsingAnimator = false; if (isDismissing) { if (ShouldAnimateUsingAnimator) { Animator.AnimateTransition(_transitionContext); didAnimateUsingAnimator = true; } else { var isPositiveDelta = verticalDelta >= 0; var modifier = isPositiveDelta ? 1 : -1; if (fromView == null) { finalPageViewCenterPount = new CGPoint(0.0f, 0.0f); } else { var finalCenterY = fromView.Bounds.GetMidY() + modifier * fromView.Bounds.Height; finalPageViewCenterPount = new CGPoint(fromView.Center.X, finalCenterY); } animationDuration = Math.Abs(finalPageViewCenterPount.Y - viewToPan.Center.Y) / Math.Abs(velocityY); animationDuration = Math.Min(animationDuration, PhotoDismissalInteractionControllerPanDismissMaximumDuration); animationCurve = UIViewAnimationOptions.CurveEaseOut; finalBackgroundAlpha = 0.0f; } } if (!didAnimateUsingAnimator) { UIView.Animate(animationDuration, 0, animationCurve, () => { viewToPan.Center = finalPageViewCenterPount; fromView.BackgroundColor = fromView.BackgroundColor.ColorWithAlpha(finalBackgroundAlpha); }, () => { if (isDismissing) { _transitionContext.FinishInteractiveTransition(); } else { _transitionContext.CancelInteractiveTransition(); } if (ViewToHideWhenBeginningTransition != null) { ViewToHideWhenBeginningTransition.Alpha = 1.0f; } _transitionContext.CompleteTransition(isDismissing && !_transitionContext.TransitionWasCancelled); _transitionContext = null; } ); } else { _transitionContext = null; } }
public void DragContentView(UIPanGestureRecognizer panGesture) { if (ShouldStayOpen || mainView == null) return; var frame = mainView.Frame; var translation = panGesture.TranslationInView (View).Y; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startY = frame.Y; } else if (panGesture.State == UIGestureRecognizerState.Changed) { frame.Y = translation + startY; if (frame.Y < 0) frame.Y = 0; else if (frame.Y > frame.Height) frame.Y = menuHeight; SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { var velocity = panGesture.VelocityInView(View).Y; //Console.WriteLine (velocity); var newY = translation + startY; Console.WriteLine (translation + startY); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startY < menuHeight ? (newY > (menuHeight / 2)) : newY > menuHeight; if(show) ShowMenu(); else HideMenu(); } }
private void PanRight(UIPanGestureRecognizer panGesture) { var frame = mainView.Frame; var translation = panGesture.TranslationInView(View).X; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startX = frame.X; } else if (panGesture.State == UIGestureRecognizerState.Changed) { //don't allow getsture to close if (!GestureToClose && (translation + startX) > startX) translation = 0; //don't allow gesture to open if (!GestureToOpen && (translation + startX) < startX) translation = 0; frame.X = translation + startX; if (frame.X < -menuWidth) frame.X = -menuWidth; else if (frame.X > 0) frame.X = 0; SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { var velocity = panGesture.VelocityInView(View).X; //Console.WriteLine (velocity); var newX = translation + startX; Console.WriteLine(translation + startX); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startX < menuWidth ? (newX > (menuWidth / 2)) : newX > menuWidth; show = !show;//swap //don't allow flick open if (show && !GestureToOpen) return; //don't allow flick close if (!show && !GestureToClose) return; if (show) ShowMenu(); else HideMenu(); } }
void OnPanGesture(UIPanGestureRecognizer obj) { switch( obj.State ) { case UIGestureRecognizerState.Began: { // when panning begins, clear our pan values PanLastPos = new CGPoint( 0, 0 ); PanDir = 0; break; } case UIGestureRecognizerState.Changed: { // use the velocity to determine the direction of the pan CGPoint currVelocity = obj.VelocityInView( View ); if( currVelocity.X < 0 ) { PanDir = -1; } else { PanDir = 1; } // Update the positions of the cards CGPoint absPan = obj.TranslationInView( View ); CGPoint delta = new CGPoint( absPan.X - PanLastPos.X, 0 ); PanLastPos = absPan; TryPanSpringboard( delta ); break; } case UIGestureRecognizerState.Ended: { CGPoint currVelocity = obj.VelocityInView( View ); float restingPoint = (float)0.00f;//(View.Layer.Bounds.Width / 2); float currX = (float) (View.Layer.Position.X - restingPoint); // if they slide at least a third of the way, allow a switch float toggleThreshold = (PrivatePrimaryContainerConfig.SlideAmount_iOS / 3); // check whether the springboard is open, because that changes the // context of hte user's intention if( SpringboardRevealed == true ) { // since it's open, close it if it crosses the closeThreshold // OR velocty is high float closeThreshold = PrivatePrimaryContainerConfig.SlideAmount_iOS - toggleThreshold; if( currX < closeThreshold || currVelocity.X < -1000 ) { RevealSpringboard( false ); } else { RevealSpringboard( true ); } } else { // since it's closed, allow it to open as long as it's beyond toggleThreshold // OR velocity is high if( currX > toggleThreshold || currVelocity.X > 1000 ) { RevealSpringboard( true ); } else { RevealSpringboard( false ); } } break; } } }
/// <summary> /// Pan the specified view. /// </summary> private void Pan(UIView view) { if (_panGesture.State == UIGestureRecognizerState.Began) { _panOriginX = view.Frame.X; if (MenuLocation == MenuLocations.Left) { _ignorePan = _panGesture.LocationInView(view).X > 50; } else { _ignorePan = _panGesture.LocationInView(view).X < view.Bounds.Width - 50; } } else if (!_ignorePan && (_panGesture.State == UIGestureRecognizerState.Changed)) { var t = _panGesture.TranslationInView(view).X; if (MenuLocation == MenuLocations.Left) { if ((t > 0 && !IsOpen) || (t < 0 && IsOpen)) { if (t > MenuWidth) { t = MenuWidth; } else if (t < -MenuWidth && IsOpen) { t = MenuWidth; } if (_panOriginX + t <= MenuWidth) { view.Frame = new RectangleF(_panOriginX + t, view.Frame.Y, view.Frame.Width, view.Frame.Height); MenuAreaController.View.Frame = new RectangleF(_panOriginX + t - MenuWidth, MenuAreaController.View.Frame.Y, MenuAreaController.View.Frame.Width, MenuAreaController.View.Frame.Height); //view.Alpha = 1.0f - ((_panOriginX + t) / MenuWidth)/2; _shadownOverlayContent.Alpha = ((_panOriginX + t) / MenuWidth) * 0.7f; _shadownOverlayMenu.Alpha = 1.0f - ((_panOriginX + t) / MenuWidth); } ShowShadowWhileDragging(); } } else if (MenuLocation == MenuLocations.Right) { if ((t < 0 && !IsOpen) || (t > 0 && IsOpen)) { if (t < -MenuWidth) { t = -MenuWidth; } else if (t > MenuWidth) { t = MenuWidth; } if (_panOriginX + t <= 0) { view.Frame = new RectangleF(_panOriginX + t, view.Frame.Y, view.Frame.Width, view.Frame.Height); } ShowShadowWhileDragging(); } } } else if (!_ignorePan && (_panGesture.State == UIGestureRecognizerState.Ended || _panGesture.State == UIGestureRecognizerState.Cancelled)) { var t = _panGesture.TranslationInView(view).X; var velocity = _panGesture.VelocityInView(view).X; if ((MenuLocation == MenuLocations.Left && IsOpen && t < 0) || (MenuLocation == MenuLocations.Right && IsOpen && t > 0)) { if (view.Frame.X > -view.Frame.Width / 2) { CloseMenu(); } else { UIView.Animate(_slideSpeed, 0, UIViewAnimationOptions.CurveEaseInOut, () => { view.Frame = new RectangleF(-MenuWidth, view.Frame.Y, view.Frame.Width, view.Frame.Height); }, () => { }); } } if ((MenuLocation == MenuLocations.Left && (velocity > FlingVelocity || view.Frame.X > (MenuWidth * FlingPercentage))) || (MenuLocation == MenuLocations.Right && (velocity < -FlingVelocity || view.Frame.X < -(MenuWidth * FlingPercentage)))) { OpenMenu(); } else { UIView.Animate(_slideSpeed, 0, UIViewAnimationOptions.CurveEaseInOut, () => { view.Frame = new RectangleF(0, 0, view.Frame.Width, view.Frame.Height); }, () => { }); } } }
private void PanTop(UIPanGestureRecognizer panGesture) { var frame = mainView.Frame; var translation = panGesture.TranslationInView (View).Y; //Console.WriteLine (translation); if (panGesture.State == UIGestureRecognizerState.Began) { startY = frame.Y; } else if (panGesture.State == UIGestureRecognizerState.Changed) { //don't allow getsture to close if (!GestureToClose && (translation + startY) < startY) translation = 0; //don't allow gesture to open if (!GestureToOpen && (translation + startY) > startY) translation = 0; frame.Y = translation + startY; if (frame.Y < 0) frame.Y = 0; else if (frame.Y > frame.Height) frame.Y = menuHeight; SetLocation(frame); } else if (panGesture.State == UIGestureRecognizerState.Ended) { var velocity = panGesture.VelocityInView(View).Y; //Console.WriteLine (velocity); var newY = translation + startY; Console.WriteLine (translation + startY); bool show = (Math.Abs(velocity) > sidebarFlickVelocity) ? (velocity > 0) : startY < menuHeight ? (newY > (menuHeight / 2)) : newY > menuHeight; //don't allow flick open if (show && !GestureToOpen) return; //don't allow flick close if (!show && !GestureToClose) return; if(show) ShowMenu(); else HideMenu(); } }