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)); } } } }
private void PinchGestureRecognizerHandler(UIPinchGestureRecognizer gestureRecognizer) { Stopwatch sw = Stopwatch.StartNew(); RefreshArguments arguments = CollectArguments(gestureRecognizer); if (middlePoint.Equals(CGPoint.Empty)) { if (gestureRecognizer.NumberOfTouches <= 1) { return; } CGPoint point1 = gestureRecognizer.LocationOfTouch(0, containerView); CGPoint point2 = gestureRecognizer.LocationOfTouch(1, containerView); nfloat x = point1.X - point2.X; nfloat y = point1.Y - point2.Y; middlePoint = new CGPoint(point1.X + x, point1.Y + y); } if (tileSize == 0) { zoomLevel = arguments.ZoomLevel; tileSize = arguments.TileSize; extentWidth = containerView.CurrentExtent.Width; extentHeight = containerView.CurrentExtent.Height; } arguments.Scale = gestureRecognizer.Scale; arguments.ZoomLevel = zoomLevel * gestureRecognizer.Scale; arguments.TileSize = (int)(tileSize * gestureRecognizer.Scale); txtZoomLevel.Text = arguments.ZoomLevel.ToString(); txtTileSize.Text = arguments.TileSize.ToString(); nfloat newLeft = middlePoint.X - gestureRecognizer.Scale * middlePoint.X; nfloat newTop = middlePoint.Y - gestureRecognizer.Scale * middlePoint.Y; nfloat newWidth = extentWidth * gestureRecognizer.Scale; nfloat newHeight = extentHeight * gestureRecognizer.Scale; containerView.CurrentExtent = new CGRect(newLeft, newTop, newWidth, newHeight); containerView.RefreshZoomTileView(arguments); if (gestureRecognizer.State == UIGestureRecognizerState.Ended) { middlePoint = CGPoint.Empty; zoomLevel = 0.0f; tileSize = 0; extentWidth = 0.0f; extentHeight = 0.0f; } sw.Stop(); GestureTimeMonitorAction(sw.ElapsedMilliseconds); }
private void _zoomStart(UIPinchGestureRecognizer recognizer) { if (embeddingView == null || previewLayer == null) { return; } var allTouchesOnPreviewLayer = true; var numTouch = recognizer.NumberOfTouches; for (int i = 0; i < numTouch; i++) { var location = recognizer.LocationOfTouch(i, embeddingView); var convertedTouch = previewLayer.ConvertPointFromLayer(location, previewLayer.SuperLayer); if (!previewLayer.Contains(convertedTouch)) { allTouchesOnPreviewLayer = false; break; } } if (allTouchesOnPreviewLayer) { _zoom(recognizer.Scale); } }
public void OnPinchGesture(UIPinchGestureRecognizer sender) { var location0 = sender.LocationOfTouch(0, sender.View); var position0 = GetOffsetPosition(new Vector2(location0.X, location0.Y), true); PointF location1; Vector2 position1; if (sender.NumberOfTouches > 1) { location1 = sender.LocationOfTouch(1, sender.View); position1 = GetOffsetPosition(new Vector2(location1.X, location1.Y), true); } else { location1 = location0; position1 = position0; } var delta0 = position0 - _previousPinchPositions [0].GetValueOrDefault(position0); var delta1 = position1 - _previousPinchPositions [1].GetValueOrDefault(position1); TouchPanel.GestureList.Enqueue(new GestureSample( GestureType.Pinch, new TimeSpan(DateTime.Now.Ticks), position0, position1, delta0, delta1)); if (sender.State == UIGestureRecognizerState.Ended || sender.State == UIGestureRecognizerState.Cancelled || sender.State == UIGestureRecognizerState.Failed) { _previousPinchPositions [0] = null; _previousPinchPositions [1] = null; } else { _previousPinchPositions [0] = position0; _previousPinchPositions [1] = position1; } }
public static CGPoint AnchorInView(this UIPinchGestureRecognizer gesture, UIView view) { nint touchNumber = gesture.NumberOfTouches; nfloat touchXSum = 0; nfloat touchYSum = 0; for (int i = 0; i < touchNumber; i++) { CGPoint location = gesture.LocationOfTouch(i, view); touchXSum += location.X; touchYSum += location.Y; } nfloat touchX = touchXSum / touchNumber; nfloat touchY = touchYSum / touchNumber; return(new CGPoint(touchX, touchY)); }
public void PinchGestureRecognizer(UIPinchGestureRecognizer sender) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Pinch, new TimeSpan(_nowUpdate.Ticks), new Vector2(sender.LocationOfTouch(0, sender.View)), new Vector2(sender.LocationOfTouch(1, sender.View)), new Vector2(0, 0), new Vector2(0, 0))); }
public void PinchGestureRecognizer(UIPinchGestureRecognizer sender) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Pinch, new TimeSpan(_nowUpdate.Ticks), new Vector2 (sender.LocationOfTouch(0,sender.View)), new Vector2 (sender.LocationOfTouch(1,sender.View)), new Vector2(0,0), new Vector2(0,0))); }
// 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)); } } } }
public void PinchGestureRecognizer(UIPinchGestureRecognizer sender) { if (sender.State==UIGestureRecognizerState.Ended || sender.State==UIGestureRecognizerState.Cancelled || sender.State==UIGestureRecognizerState.Failed || sender.NumberOfTouches<2) { _lastPinchPosition1 = new Vector2(0,0); _lastPinchPosition2 = new Vector2(0,0); } else { Vector2 position1 = GetOffsetPosition(new Vector2(sender.LocationOfTouch(0,sender.View)), true); Vector2 position2 = GetOffsetPosition(new Vector2(sender.LocationOfTouch(1,sender.View)), true); if (_lastPinchPosition1.X == 0 && _lastPinchPosition1.Y == 0) _lastPinchPosition1 = position1; if (_lastPinchPosition2.X == 0 && _lastPinchPosition2.Y == 0) _lastPinchPosition2 = position2; TouchPanel.GestureList.Enqueue( new GestureSample( GestureType.Pinch, new TimeSpan(_nowUpdate.Ticks), position1, position2, position1 - _lastPinchPosition1, position2 - _lastPinchPosition2 )); _lastPinchPosition1 = position1; _lastPinchPosition2 = position2; } }
public void OnPinchGesture (UIPinchGestureRecognizer sender) { var location0 = sender.LocationOfTouch (0, sender.View); var position0 = GetOffsetPosition (new Vector2 (location0.X, location0.Y), true); PointF location1; Vector2 position1; if (sender.NumberOfTouches > 1) { location1 = sender.LocationOfTouch (1, sender.View); position1 = GetOffsetPosition (new Vector2 (location1.X, location1.Y), true); } else { location1 = location0; position1 = position0; } var delta0 = position0 - _previousPinchPositions [0].GetValueOrDefault (position0); var delta1 = position1 - _previousPinchPositions [1].GetValueOrDefault (position1); TouchPanel.GestureList.Enqueue (new GestureSample ( GestureType.Pinch, new TimeSpan (DateTime.Now.Ticks), position0, position1, delta0, delta1)); if (sender.State == UIGestureRecognizerState.Ended || sender.State == UIGestureRecognizerState.Cancelled || sender.State == UIGestureRecognizerState.Failed) { _previousPinchPositions [0] = null; _previousPinchPositions [1] = null; } else { _previousPinchPositions [0] = position0; _previousPinchPositions [1] = position1; } }
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; } }
public void PinchGestureRecognizer(UIPinchGestureRecognizer sender) { var enabledGestures = TouchPanel.EnabledGestures; if ((enabledGestures & GestureType.Pinch) != 0) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Pinch, new TimeSpan(_now.Ticks), new Vector2 (sender.LocationOfTouch(0,sender.View)), new Vector2 (sender.LocationOfTouch(1,sender.View)), new Vector2(0,0), new Vector2(0,0))); } }