private void PinchGesture(UIPinchGestureRecognizer pPinch) { if (pPinch.State == UIGestureRecognizerState.Ended) { _PinchStart = null; return; } if (pPinch.State == UIGestureRecognizerState.Began) { CGPoint start = pPinch.LocationInView(null); _PinchStart = new SKPoint((float)start.X, (float)start.Y); } CGPoint current = pPinch.LocationInView(null); _Offset = new SKPoint(Math.Max((float)(current.X - _PinchStart?.X), 0), Math.Max((float)(_PinchStart?.Y - current.Y), 0)); _Scale = Math.Max(Math.Min((float)pPinch.Scale, 5), 1); /*if (Math.Abs(_Scale - 1f) < 0.001) * { * _Offset = new SKPoint(); * _Scale = 1; * }*/ SetNeedsDisplay(); }
private void PinchGesture(UIPinchGestureRecognizer recognizer) { if (_map.Lock) { return; } if ((int)recognizer.NumberOfTouches < 2) { return; } if (recognizer.State == UIGestureRecognizerState.Began) { _oldDist = 1; _currentMid = (CGPoint)recognizer.LocationInView((UIView)this); } float scale = 1 - (_oldDist - (float)recognizer.Scale); if (scale > 0.5 && scale < 1.5) { if (_oldDist != (float)recognizer.Scale) { _oldDist = (float)recognizer.Scale; _currentMid = (CGPoint)recognizer.LocationInView((UIView)this); _previousMid = new CGPoint(_currentMid.X, _currentMid.Y); _map.Viewport.Center = _map.Viewport.ScreenToWorld( _currentMid.X, _currentMid.Y); _map.Viewport.Resolution = _map.Viewport.Resolution / scale; _map.Viewport.Center = _map.Viewport.ScreenToWorld( (_map.Viewport.Width - _currentMid.X), (_map.Viewport.Height - _currentMid.Y)); } _map.Viewport.Transform( _currentMid.X, _currentMid.Y, _previousMid.X, _previousMid.Y); RefreshGraphics(); } var majorChange = (recognizer.State == UIGestureRecognizerState.Ended); _map.ViewChanged(majorChange); }
protected void PinchDetected(UIPinchGestureRecognizer pinch) { if (pinch.State != UIGestureRecognizerState.Ended) { return; } var location = pinch.LocationInView(CollectionView); var path = CollectionView.IndexPathForItemAtPoint(location); if (path == null) { var visiblecells = CollectionView.IndexPathsForVisibleItems; int center = visiblecells.Length / 2; path = visiblecells [center]; } if (pinch.Scale > 1) { _fasize.Increment(); } if (pinch.Scale < 1) { _fasize.Decrement(); } Zoom(path); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void HandlePinchAction() { if (pinchGesture.State == UIGestureRecognizerState.Began) { initialPinchTimeStart = timeStart; initialPinchTimeEnd = timeEnd; relativePos = pinchGesture.LocationInView(this).X / Frame.Size.Width; } else if (pinchGesture.State == UIGestureRecognizerState.Ended) { readyToDataUpdate = true; } double oldFrame = (initialPinchTimeEnd - initialPinchTimeStart).TotalSeconds; double newFrame = oldFrame / pinchGesture.Scale; if (newFrame > new TimeSpan(2000, 0, 0, 0, 0).TotalSeconds) { newFrame = oldFrame; } timeStart = initialPinchTimeStart.AddSeconds((oldFrame - newFrame) * relativePos); if (timeStart < DataManager.unixEpoch) { timeStart = DataManager.unixEpoch; } timeEnd = timeStart.AddSeconds(newFrame); SetNeedsDisplay(); //Console.WriteLine("state: " + pinchGesture.State + ", timeStart: " + timeStart + "timeEnd: " + timeEnd + ", scale: " + pinchGesture.Scale + ", relativePos: " + relativePos); }
void onPinchUpdated(UIPinchGestureRecognizer gesture) { var pinchCenter = gesture.LocationInView(gesture.View); switch (gesture.State) { case UIGestureRecognizerState.Began: layout.ScaleHourHeight(gesture.Scale, pinchCenter); break; case UIGestureRecognizerState.Changed: layout.ScaleHourHeight(gesture.Scale, pinchCenter); gesture.Scale = 1; break; case UIGestureRecognizerState.Ended: layout.ScaleHourHeight(gesture.Scale, pinchCenter); layout.OnScalingEnded(); break; case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: break; } }
private void OnPlotPinch(UIPinchGestureRecognizer recognizer) { var location = recognizer.LocationInView(Plot); if (recognizer.State == UIGestureRecognizerState.Began) { anchorPoint = location; } if (recognizer.State == UIGestureRecognizerState.Ended) { Plot.ZoomTo(recognizer.Scale, anchorPoint); PrimaryYAxis.ZoomTo(recognizer.Scale, anchorPoint.Y); PrimaryXAxis.ZoomTo(recognizer.Scale, anchorPoint.X); Grid.ZoomTo(recognizer.Scale, anchorPoint); anchorPoint = CGPoint.Empty; } else { Plot.ZoomBy(recognizer.Scale, anchorPoint); PrimaryYAxis.ZoomBy(recognizer.Scale, anchorPoint.Y); PrimaryXAxis.ZoomBy(recognizer.Scale, anchorPoint.X); Grid.ZoomBy(recognizer.Scale, anchorPoint); } }
public void HandlePinch(UIPinchGestureRecognizer sender) { if (sender.NumberOfTouches < 2) { return; } PointF point1 = sender.LocationOfTouch(0, sender.View); PointF point2 = sender.LocationOfTouch(1, sender.View); float distance = (float)Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y)); PointF point = sender.LocationInView(sender.View); if (sender.State == UIGestureRecognizerState.Began) { if (HasActiveInteraction) { return; } initialPinchDistance = distance; initialPinchPoint = point; HasActiveInteraction = true; InteractionBegan(point); return; } if (!HasActiveInteraction) { return; } switch (sender.State) { case UIGestureRecognizerState.Changed: float offsetX = point.X - initialPinchPoint.X; float offsetY = point.Y - initialPinchPoint.Y; float distanceDelta = distance - initialPinchDistance; if (NavigationOperation == UINavigationControllerOperation.Pop) { distanceDelta = -distanceDelta; } SizeF size = collectionView.Bounds.Size; float dimension = (float)Math.Sqrt(size.Width * size.Width + size.Height * size.Height); float progress = (float)Math.Max(Math.Min(distanceDelta / dimension, 1.0), 0.0); Update(progress, new UIOffset(offsetX, offsetY)); break; case UIGestureRecognizerState.Ended: EndInteraction(true); break; case UIGestureRecognizerState.Cancelled: EndInteraction(false); break; } }
// action method for our pinch gesture recognizer public void HandlePinch(UIPinchGestureRecognizer sender) { // here we want to end the transition interaction if the user stops or finishes the pinch gesture if (sender.State == UIGestureRecognizerState.Ended) { EndInteraction(true); } else if (sender.State == UIGestureRecognizerState.Cancelled) { EndInteraction(false); } else if (sender.NumberOfTouches == 2) { // here we expect two finger touch PointF point = sender.LocationInView(sender.View); // get the main touch point PointF point1 = sender.LocationOfTouch(0, sender.View); // return the locations of each gesture’s touches in the local coordinate system of a given view PointF point2 = sender.LocationOfTouch(1, sender.View); float distance = (float)Math.Sqrt((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y)); if (sender.State == UIGestureRecognizerState.Began) { // start the pinch in our out if (!HasActiveInteraction) { initialPinchDistance = distance; initialPinchPoint = point; HasActiveInteraction = true; // the transition is in active motion InteractionBegan(point); } } if (HasActiveInteraction) { if (sender.State == UIGestureRecognizerState.Changed) { // update the progress of the transtition as the user continues to pinch float offsetX = point.X - initialPinchPoint.X; float offsetY = point.Y - initialPinchPoint.Y; float distanceDelta = distance - initialPinchDistance; if (NavigationOperation == UINavigationControllerOperation.Pop) { distanceDelta = -distanceDelta; } SizeF size = collectionView.Bounds.Size; float dimension = (float)Math.Sqrt(size.Width * size.Width + size.Height * size.Height); float progress = (float)Math.Max(Math.Min(distanceDelta / dimension, 1.0), 0.0); // tell our UICollectionViewTransitionLayout subclass (transitionLayout) // the progress state of the pinch gesture Update(progress, new UIOffset(offsetX, offsetY)); } } } }
public void handlePinchGesture (UIPinchGestureRecognizer sender) { PinchLayout pinchLayout = (PinchLayout) CollectionView.CollectionViewLayout; switch (sender.State) { case UIGestureRecognizerState.Began: CGPoint initialPinchPoint = sender.LocationInView (CollectionView); pinchLayout.pinchedCellPath = CollectionView.IndexPathForItemAtPoint (initialPinchPoint); break; case UIGestureRecognizerState.Changed: pinchLayout.setPinchedCellScale ((float)sender.Scale); pinchLayout.setPinchedCellCenter (sender.LocationInView (CollectionView)); break; default: CollectionView.PerformBatchUpdates (delegate { pinchLayout.pinchedCellPath = null; pinchLayout.setPinchedCellScale (1.0f); }, null); break; } }
public void handlePinchGesture(UIPinchGestureRecognizer sender) { PinchLayout pinchLayout = (PinchLayout)CollectionView.CollectionViewLayout; switch (sender.State) { case UIGestureRecognizerState.Began: PointF initialPinchPoint = sender.LocationInView(CollectionView); pinchLayout.pinchedCellPath = CollectionView.IndexPathForItemAtPoint(initialPinchPoint); break; case UIGestureRecognizerState.Changed: pinchLayout.setPinchedCellScale(sender.Scale); pinchLayout.setPinchedCellCenter(sender.LocationInView(CollectionView)); break; default: CollectionView.PerformBatchUpdates(delegate { pinchLayout.pinchedCellPath = null; pinchLayout.setPinchedCellScale(1.0f); }, null); break; } }
public void HandlePinchGesture(UIPinchGestureRecognizer aPinchGestureRecognizer) { PointF interactionPoint = aPinchGestureRecognizer.LocationInView(this); ScreenPoint point1 = new ScreenPoint(interactionPoint.X, interactionPoint.Y); foreach (var item in plot.Axes) { item.ZoomAt(pinchGestureRecognizer.Scale, point1); } pinchGestureRecognizer.Scale = 1.0f; SetNeedsDisplay(); }
private void HandlerPick(UIPinchGestureRecognizer sender) { ARSCNView pinchScene = sender.View as ARSCNView; CoreGraphics.CGPoint pinchLocation = sender.LocationInView(pinchScene); SCNHitTestResult[] hitTest = pinchScene.HitTest(pinchLocation, new SCNHitTestOptions()); if (hitTest?.Any() != true) { return; } SCNNode node = hitTest.First().Node; SCNAction pinchAction = SCNAction.ScaleBy(sender.Scale, 0); node.RunAction(pinchAction); sender.Scale = 1.0f; }
void HandlePinchGesture(UIPinchGestureRecognizer sender) { SCNView areaPanned = sender.View as SCNView; CGPoint point = sender.LocationInView(areaPanned); SCNHitTestResult[] hitResults = areaPanned.HitTest(point, new SCNHitTestOptions()); SCNHitTestResult hit = hitResults.FirstOrDefault(); if (hit != null) { SCNNode node = hit.Node; float scaleX = (float)sender.Scale * node.Scale.X; float scaleY = (float)sender.Scale * node.Scale.Y; node.Scale = new SCNVector3(scaleX, scaleY, zPosition / 2); sender.Scale = 1; // Reset the node scale value } }
private Xamarin.Forms.PinchGestureUpdatedEventArgs CreatePinchEventArgs(UIView uiView, UIPinchGestureRecognizer pgr) { Xamarin.Forms.GestureStatus status; switch (pgr.State) { case UIGestureRecognizerState.Began: status = Xamarin.Forms.GestureStatus.Started; break; case UIGestureRecognizerState.Changed: status = Xamarin.Forms.GestureStatus.Running; break; case UIGestureRecognizerState.Ended: status = Xamarin.Forms.GestureStatus.Completed; break; case UIGestureRecognizerState.Cancelled: status = Xamarin.Forms.GestureStatus.Canceled; break; default: return(null); } CGPoint location = pgr.LocationInView(uiView); Xamarin.Forms.PinchGestureUpdatedEventArgs args = new Xamarin.Forms.PinchGestureUpdatedEventArgs ( status, pgr.Scale, new Xamarin.Forms.Point(location.X, location.Y) ); return(args); }
public void HandlePinch (UIPinchGestureRecognizer sender) { if (sender.NumberOfTouches < 2) return; PointF point1 = sender.LocationOfTouch (0, sender.View); PointF point2 = sender.LocationOfTouch (1, sender.View); float distance = (float) Math.Sqrt ((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y)); PointF point = sender.LocationInView (sender.View); if (sender.State == UIGestureRecognizerState.Began) { if (HasActiveInteraction) return; initialPinchDistance = distance; initialPinchPoint = point; HasActiveInteraction = true; InteractionBegan (point); return; } if (!HasActiveInteraction) return; switch (sender.State) { case UIGestureRecognizerState.Changed: float offsetX = point.X - initialPinchPoint.X; float offsetY = point.Y - initialPinchPoint.Y; float distanceDelta = distance - initialPinchDistance; if (NavigationOperation == UINavigationControllerOperation.Pop) distanceDelta = -distanceDelta; SizeF size = collectionView.Bounds.Size; float dimension = (float)Math.Sqrt (size.Width * size.Width + size.Height * size.Height); float progress = (float) Math.Max (Math.Min (distanceDelta / dimension, 1.0), 0.0); Update (progress, new UIOffset (offsetX, offsetY)); break; case UIGestureRecognizerState.Ended: EndInteraction (true); break; case UIGestureRecognizerState.Cancelled: EndInteraction (false); break; } }
private void HandlePinchGestureRecognizer(UIPinchGestureRecognizer sender) { if (sender.State == UIGestureRecognizerState.Began) { _initialZoom = Zoom; _initialContentOffset = WaveFormView.ContentOffset; UIView.Animate(0.2, () => _lblZoom.Alpha = 0.9f); } else if (sender.State == UIGestureRecognizerState.Ended) { UIView.Animate(0.2, 0.8, UIViewAnimationOptions.CurveEaseOut, () => _lblZoom.Alpha = 0, () => {}); } var location = sender.LocationInView(this); float newZoom = _initialZoom * _pinchGesture.Scale; float deltaZoom = newZoom / Zoom; float originPointX = IsAutoScrollEnabled ? WaveFormView.ContentOffset.X + (Frame.Width / 2) : location.X + WaveFormView.ContentOffset.X; float distanceToOffsetX = originPointX - WaveFormView.ContentOffset.X; float contentOffsetX = (originPointX * deltaZoom) - distanceToOffsetX; Zoom = Math.Max(1, newZoom); SetContentOffsetX(contentOffsetX); _lblZoom.Text = (Zoom * 100).ToString("0") + "%"; //Console.WriteLine("HandlePinchGestureRecognizer - initialZoom: {0} newZoom: {1}", _initialZoom, newZoom); }
private void PinchGesture(UIPinchGestureRecognizer recognizer) { if (_map.Lock) return; if ((int)recognizer.NumberOfTouches < 2) return; if (recognizer.State == UIGestureRecognizerState.Began) { _oldDist = 1; _currentMid = (CGPoint)recognizer.LocationInView((UIView)this); } float scale = 1 - (_oldDist - (float)recognizer.Scale); if (scale > 0.5 && scale < 1.5) { if (_oldDist != (float)recognizer.Scale) { _oldDist = (float)recognizer.Scale; _currentMid = (CGPoint)recognizer.LocationInView((UIView)this); _previousMid = new CGPoint(_currentMid.X, _currentMid.Y); _map.Viewport.Center = _map.Viewport.ScreenToWorld( _currentMid.X, _currentMid.Y); _map.Viewport.Resolution = _map.Viewport.Resolution / scale; _map.Viewport.Center = _map.Viewport.ScreenToWorld( (_map.Viewport.Width - _currentMid.X), (_map.Viewport.Height - _currentMid.Y)); } _map.Viewport.Transform( _currentMid.X, _currentMid.Y, _previousMid.X, _previousMid.Y); RefreshGraphics(); } var majorChange = (recognizer.State == UIGestureRecognizerState.Ended); _map.ViewChanged(majorChange); }
protected void PinchDetected(UIPinchGestureRecognizer pinch) { if (pinch.State != UIGestureRecognizerState.Ended) { return; } var location = pinch.LocationInView (CollectionView); var path = CollectionView.IndexPathForItemAtPoint (location); if (path == null) { var visiblecells = CollectionView.IndexPathsForVisibleItems; int center = visiblecells.Length / 2; path = visiblecells [center]; } if (pinch.Scale > 1) { _fasize.Increment (); } if (pinch.Scale < 1) { _fasize.Decrement (); } Zoom (path); }
// action method for our pinch gesture recognizer public void HandlePinch (UIPinchGestureRecognizer sender) { // here we want to end the transition interaction if the user stops or finishes the pinch gesture if (sender.State == UIGestureRecognizerState.Ended) { EndInteraction (true); } else if (sender.State == UIGestureRecognizerState.Cancelled) { EndInteraction (false); } else if (sender.NumberOfTouches == 2) { // here we expect two finger touch CGPoint point = sender.LocationInView (sender.View); // get the main touch point CGPoint point1 = sender.LocationOfTouch (0, sender.View); // return the locations of each gesture’s touches in the local coordinate system of a given view CGPoint point2 = sender.LocationOfTouch (1, sender.View); float distance = (float)Math.Sqrt ((point1.X - point2.X) * (point1.X - point2.X) + (point1.Y - point2.Y) * (point1.Y - point2.Y)); if (sender.State == UIGestureRecognizerState.Began) { // start the pinch in our out if (!HasActiveInteraction) { initialPinchDistance = distance; initialPinchPoint = point; HasActiveInteraction = true; // the transition is in active motion InteractionBegan (point); } } if (HasActiveInteraction) { if (sender.State == UIGestureRecognizerState.Changed) { // update the progress of the transtition as the user continues to pinch float offsetX = (float)point.X - (float)initialPinchPoint.X; float offsetY = (float)point.Y - (float)initialPinchPoint.Y; float distanceDelta = distance - initialPinchDistance; if (NavigationOperation == UINavigationControllerOperation.Pop) distanceDelta = -distanceDelta; CGSize size = collectionView.Bounds.Size; float dimension = (float)Math.Sqrt (size.Width * size.Width + size.Height * size.Height); float progress = (float)Math.Max (Math.Min (distanceDelta / dimension, 1.0), 0.0); // tell our UICollectionViewTransitionLayout subclass (transitionLayout) // the progress state of the pinch gesture Update (progress, new UIOffset (offsetX, offsetY)); } } } }