void HandleLongGesture(UIGestureRecognizer gesture) { if (_editModeEnabled) { return; } switch (gesture.State) { case UIGestureRecognizerState.Began: _selIndPath = KeysCollectionView.IndexPathForItemAtPoint(gesture.LocationInView(View)); if (_selIndPath != null) { KeysCollectionView.BeginInteractiveMovementForItem(_selIndPath); } break; case UIGestureRecognizerState.Changed: KeysCollectionView.UpdateInteractiveMovement(gesture.LocationInView(View)); break; case UIGestureRecognizerState.Ended: KeysCollectionView.EndInteractiveMovement(); break; default: KeysCollectionView.CancelInteractiveMovement(); break; } }
void AdjustAnchorPointForGestureRecognizer(UIGestureRecognizer gestureRecognizer) { if (gestureRecognizer.State == UIGestureRecognizerState.Began) { UIView piece = gestureRecognizer.View; PointF locationInView = gestureRecognizer.LocationInView(piece); PointF locationInSuperview = gestureRecognizer.LocationInView(piece.Superview); piece.Layer.AnchorPoint = new PointF(locationInView.X / piece.Bounds.Size.Width, locationInView.Y / piece.Bounds.Size.Height); piece.Center = locationInSuperview; } }
void AdjustAnchorPointForGestureRecognizer(UIGestureRecognizer gestureRecognizer) { if (gestureRecognizer.State == UIGestureRecognizerState.Began) { var image = gestureRecognizer.View; var locationInView = gestureRecognizer.LocationInView(image); var locationInSuperview = gestureRecognizer.LocationInView(image.Superview); image.Layer.AnchorPoint = new CGPoint(locationInView.X / image.Bounds.Size.Width, locationInView.Y / image.Bounds.Size.Height); image.Center = locationInSuperview; } }
void adjustAnchorPointForGestureRecognizer(UIGestureRecognizer gesture) { if (!anchorPointUpdated) { UIView piece = gesture.View; CGPoint locationInView = gesture.LocationInView(piece); CGPoint locationInSuperview = gesture.LocationInView(piece.Superview); piece.Layer.AnchorPoint = new CGPoint(locationInView.X / piece.Bounds.Width, locationInView.Y / piece.Bounds.Height); piece.Center = locationInSuperview; anchorPointUpdated = true; } }
partial void handleTap(UIGestureRecognizer recognizer) { PointF tapPoint = recognizer.LocationInView(previewView); focus(tapPoint); expose(tapPoint); }
private static Position ConvertLocationToPosition(UIGestureRecognizer recognizer, MKMapView map) { var point = recognizer.LocationInView(map); var coordinate = map.ConvertPoint(point, map); return(new Position(coordinate.Latitude, coordinate.Longitude)); }
private void PanOrTapValue(UIGestureRecognizer recognizer) { var center = new PointF(this.Bounds.Width / 2f, this.Bounds.Height / 2f); switch (recognizer.State) { case UIGestureRecognizerState.Began: case UIGestureRecognizerState.Changed: case UIGestureRecognizerState.Ended: var point = recognizer.LocationInView(this); var dx = point.X - center.X; var dy = point.Y - center.Y; //var distance = Math.Sqrt(dx * dx + dy * dy); var angle = (float)Math.Atan2(-dy, -dx); var h = (angle + (float)Math.PI) / (2f * (float)Math.PI); this.Hue = h; break; case UIGestureRecognizerState.Failed: case UIGestureRecognizerState.Cancelled: break; default: break; } }
void FocusAndExposeTap(UIGestureRecognizer gestureRecognizer) { var location = gestureRecognizer.LocationInView(gestureRecognizer.View); var devicePoint = PreviewView.VideoPreviewLayer.CaptureDevicePointOfInterestForPoint(location); UpdateDeviceFocus(AVCaptureFocusMode.AutoFocus, AVCaptureExposureMode.AutoExpose, devicePoint, true); }
bool IsTouchOutsideOfAnyButton(UIGestureRecognizer recognizer) { var location = recognizer.LocationInView(recognizer.View); var viewWithTouchInside = recognizer.View.HitTest(location, null); return(!(viewWithTouchInside is UIButton)); }
private void MapViewMapSingleTap(object sender, UIGestureRecognizer e) { CGPoint location = e.LocationInView(View); PointShape position = ExtentHelper.ToWorldCoordinate(mapView.CurrentExtent, (float)location.X, (float)location.Y, (float)View.Frame.Width, (float)View.Frame.Height); routingLayer.Routes.Clear(); if (firstClick) { routingLayer.StartPoint = position; firstClick = false; } else { routingLayer.EndPoint = position; firstClick = true; } routingLayer.Routes.Clear(); if (routingLayer.StartPoint != null && routingLayer.EndPoint != null) { RoutingResult routingResult = routingEngine.GetRoute(routingLayer.StartPoint, routingLayer.EndPoint); routingLayer.Routes.Add(routingResult.Route); ShowTurnByTurnDirections(routingResult.RouteSegments, routingResult.Features); } layerOverlay.Refresh(); }
private void Tapped(UIGestureRecognizer gesture) { if (HitTest(gesture.LocationInView(this), null) == this) { DismissAnimated(true); } }
/// <summary> /// Gets called when the Map is clicked. /// </summary> /// <param name="sender">Sender who fired the event.</param> private void MapTapped(UIGestureRecognizer sender) { CGPoint pointInView = sender.LocationInView(this.mapView); CLLocationCoordinate2D touchCoordinates = this.mapView.ConvertPoint(pointInView, this.mapView); FieldHelper.Instance.MapTappedEvent(new Position(touchCoordinates.Latitude, touchCoordinates.Longitude), ZoomLevel(this.mapView)); }
public override bool GestureRecognizerShouldBegin(UIGestureRecognizer gesture) { if (HitTest(gesture.LocationInView(this), null) == this) { return(true); } return(false); }
private void OnSoloTap(UIGestureRecognizer gesture) { CGPoint touchPoint = new CGPoint (gesture.LocationInView(scrollView)); if(imageView.Frame.Contains(touchPoint)) { Console.WriteLine ("збс"); } }
private string DetectTappedUrl(UIGestureRecognizer tap, UILabel label, IEnumerable <LinkData> linkList) { // Create instances of NSLayoutManager, NSTextContainer and NSTextStorage var layoutManager = new NSLayoutManager(); var textContainer = new NSTextContainer(); var textStorage = new NSTextStorage(); textStorage.SetString(label.AttributedText); // Configure layoutManager and textStorage layoutManager.AddTextContainer(textContainer); textStorage.AddLayoutManager(layoutManager); // Configure textContainer textContainer.LineFragmentPadding = 0; textContainer.LineBreakMode = label.LineBreakMode; textContainer.MaximumNumberOfLines = (nuint)label.Lines; var labelSize = label.Bounds.Size; textContainer.Size = labelSize; // Find the tapped character location and compare it to the specified range var locationOfTouchInLabel = tap.LocationInView(label); var textBoundingBox = layoutManager.GetUsedRectForTextContainer(textContainer); var textContainerOffset = new CGPoint((labelSize.Width - textBoundingBox.Size.Width) * 0.0 - textBoundingBox.Location.X, (labelSize.Height - textBoundingBox.Size.Height) * 0.0 - textBoundingBox.Location.Y); nfloat labelX; switch (Element.HorizontalTextAlignment) { case TextAlignment.End: labelX = locationOfTouchInLabel.X - (labelSize.Width - textBoundingBox.Size.Width); break; case TextAlignment.Center: labelX = locationOfTouchInLabel.X - (labelSize.Width - textBoundingBox.Size.Width) / 2; break; default: labelX = locationOfTouchInLabel.X; break; } var locationOfTouchInTextContainer = new CGPoint(labelX - textContainerOffset.X, locationOfTouchInLabel.Y - textContainerOffset.Y); nfloat partialFraction = 0; var indexOfCharacter = (nint)layoutManager.CharacterIndexForPoint(locationOfTouchInTextContainer, textContainer, ref partialFraction); foreach (var link in linkList) { // Xamarin version of NSLocationInRange? if ((indexOfCharacter >= link.Range.Location) && (indexOfCharacter < link.Range.Location + link.Range.Length)) { return(link.Url); } } return(null); }
private void fireEvent(EventHandler <MousePositionEventArgs> ev, UIGestureRecognizer gesture) { var point = gesture.LocationInView(_view); if (ev != null) { ev(this, new MousePositionEventArgs((float)point.X, (float)point.Y)); } }
public static bool LocatedInView(this UIGestureRecognizer recognizer, UIView view, CGRect bounds = default(CGRect)) { var viewBounds = bounds == CGRect.Empty ? view.Bounds : bounds; var result = viewBounds.IntersectsWith( new CGRect(recognizer.LocationInView(view), CGSize.Empty)); return(result); }
// NOTE: this method only works with single line UILabels, or multi-line labels with left aligned text // Potential fix found on timbroder's comment on https://stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedstring-of-a-uilabel // Based on https://stackoverflow.com/questions/1256887/create-tap-able-links-in-the-nsattributedstring-of-a-uilabel // Based on https://samwize.com/2016/03/04/how-to-create-multiple-tappable-links-in-a-uilabel/ /// <summary> /// Determines whether the tap is within the NSRange targetRange. Returns true if so, otherwise returns false. /// </summary> /// <returns><c>true</c>, if tap was within the targetRange of the label, <c>false</c> otherwise.</returns> /// <param name="label">The label containing the text.</param> /// <param name="targetRange">The target range of the tappable text within the label.</param> /// <param name="gestureRecognizer">Gesture recognizer.</param> /// <param name="textAlignment">Text alignment of the label.</param> public static bool DidTapAttributedTextInLabel(UILabel label, NSRange targetRange, UIGestureRecognizer gestureRecognizer, UITextAlignment textAlignment) { NSLayoutManager layoutManager = new NSLayoutManager(); NSTextContainer textContainer = new NSTextContainer(CGSize.Empty); NSTextStorage textStorage = new NSTextStorage(); textStorage.SetString(label.AttributedText); // Configure layoutManager and textStorage layoutManager.AddTextContainer(textContainer); textStorage.AddLayoutManager(layoutManager); // Configure textContainer textContainer.LineFragmentPadding = 0.0f; textContainer.LineBreakMode = label.LineBreakMode; textContainer.MaximumNumberOfLines = (System.nuint)label.Lines; CGSize labelSize = label.Bounds.Size; textContainer.Size = labelSize; // Find the tapped character location and compare it to the specified range CGPoint locationOfTouchInLabel = gestureRecognizer.LocationInView(label); CGRect textBoundingBox = layoutManager.GetUsedRectForTextContainer(textContainer); // Change based on the UITextAlignment enum float multiplier; if (textAlignment == UITextAlignment.Center) { multiplier = 0.5f; } else if (textAlignment == UITextAlignment.Right) { multiplier = 1.0f; } else { // textAlignment is Left, Natural, or Justified multiplier = 0.0f; } CGPoint textContainerOffset = new CGPoint( ((labelSize.Width - textBoundingBox.Size.Width) * multiplier - textBoundingBox.Location.X), ((labelSize.Height - textBoundingBox.Size.Height) * multiplier - textBoundingBox.Location.Y) ); CGPoint locationOfTouchInTextContainer = new CGPoint(locationOfTouchInLabel.X - textContainerOffset.X, locationOfTouchInLabel.Y - textContainerOffset.Y); nfloat partialFraction = 0; int indexOfCharacter = (int)layoutManager.CharacterIndexForPoint(locationOfTouchInTextContainer, textContainer, ref partialFraction); // Xamarin version of the function NSLocationInRange (Swift equivalent is to call ```NSLocationInRange(indexOfCharacter, targetRange);``` ) // Credit to https://forums.xamarin.com/discussion/56484/need-to-put-html-into-a-label bool isInRange = (indexOfCharacter >= targetRange.Location) && (indexOfCharacter <= targetRange.Location + targetRange.Length); return(isInRange); }
public void Null() { using (var gr = new UIGestureRecognizer(Null)) { // ensure documented null-friendly methods actually are before releasing them in the wild gr.LocationInView(null); // can't call LocationOfTouch, 0 is not valid if there's no touch event // gr.LocationOfTouch (0, null); gr.RemoveTarget(null, null); } }
protected void OnMapTapped(UIGestureRecognizer sender) { if (!taqueriaAgregada) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); TaqueriaMapAnnotation pin = new TaqueriaMapAnnotation(tappedLocationCoord, "Taquería agregada", "Arrastre para mover", -1); this.map.AddAnnotation(pin); taqueriaAgregada = true;//solo puedo agregar un pin } }
public bool ShouldRecognizeSimultaneously(UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer) { // Allow multiple gesture recognizers to be recognized simultaneously if and only if the touch location is not within the touch threshold. if (gestureRecognizer == resizeRegionOfInterestGestureRecognizer) { var touchLocation = gestureRecognizer.LocationInView(gestureRecognizer.View); var closestCorner = CornerOfRect(RegionOfInterest, touchLocation); return(closestCorner == ControlCorner.None); } return(false); }
void Tapped() { if (tapRecognizer.State == UIGestureRecognizerState.Ended) { var pinchPoint = tapRecognizer.LocationInView(CollectionView); var tappedCellPath = GetIndexPathsForVisibleItems(pinchPoint); if (tappedCellPath != null) { animals.RemoveAt(tappedCellPath.Row); CollectionView.DeleteItems(new NSIndexPath[] { tappedCellPath }); } } }
protected void OnMapTapped(UIGestureRecognizer sender) { try { //predChoice(map); tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); //start annotation flow PredChoice(map, tappedLocationCoord); } catch (Exception e) { Debug.WriteLine($"CaughtException: {e}"); } }
private void PanOrTapValue(UIGestureRecognizer recognizer) { var startX = this.Bounds.GetMinX(); var startY = this.Bounds.GetMinY(); var endX = this.Bounds.GetMaxX(); var endY = this.Bounds.GetMaxY(); switch (recognizer.State) { case UIGestureRecognizerState.Began: case UIGestureRecognizerState.Changed: case UIGestureRecognizerState.Ended: var point = recognizer.LocationInView(this); var pX = point.X; var pY = point.Y; if (point.X <= startX) { pX = startX; } else if (point.X >= endX) { pX = endX; } if (point.Y <= startY) { pY = startY; } else if (point.Y >= endY) { pY = endY; } _saturation = pX / endX; _brightness = (nfloat)(Math.Abs(pY - endY) / endY); SetCrosshairPosition(); CalculateRGB(); OnChanged(EventArgs.Empty); break; case UIGestureRecognizerState.Failed: case UIGestureRecognizerState.Cancelled: break; default: break; } }
public void Dismiss(UIGestureRecognizer gestureRecognizer) { if (gestureRecognizer == null)//called dismiss somewhere via code { DismissViewController(true, null); return; } //if tap was outside DrawerViewController.View if (!View.PointInside(View.ConvertPointFromView(gestureRecognizer.LocationInView(null), View.Window), null)) { DismissViewController(true, null); return; } }
// --------------------------------------------------------- #region Event Handlers private void OnDoubleTap(UIGestureRecognizer gesture) { //double tap handled. So do not process single tap _doubleTapHandled = true; var location = gesture.LocationInView(_scrollView); if (_scrollView.ZoomScale > _scrollView.MinimumZoomScale) { ZoomToPoint(location, _scrollView.MinimumZoomScale, true); } else { ZoomToPoint(location, _scrollView.MinimumZoomScale * 3, true); } }
private void doubleTapEvent(UIGestureRecognizer sender) { // Disable gestures on preview mode if (mParent.ShouldDisplayFilledCells) { return; } if (sender.NumberOfTouches > 0) { PointF touchLocation = sender.LocationInView(this); Cell cell = getCellFromViewCoordinates(touchLocation); mParent.RemovePath(cell); } }
protected void OnMapTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); if (annotationMode) { var annotation = new MKPointAnnotation(tappedLocationCoord, "User annotation", ""); annotations.Add(annotation); map.AddAnnotation(annotation); } else { var overlay = MKCircle.Circle(tappedLocationCoord, 1000); map.AddOverlay(overlay); } }
protected void OnMapLongTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); if (annotationMode) { foreach (var annotation in annotations) { // var annotation = new MKPointAnnotation(tappedLocationCoord, "User annotation", ""); if (annotation.Coordinate.Latitude == tappedLocationCoord.Latitude && annotation.Coordinate.Longitude == tappedLocationCoord.Longitude) { map.RemoveAnnotation(annotation); annotations.Remove(annotation); } } } }
protected async void OnMapTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); map.RemoveAnnotations(map.Annotations); map.AddAnnotations(new MKPointAnnotation() { Title = "Выбранная геопозиция", Coordinate = tappedLocationCoord }); int button = await ShowAlert("Вы уверены?", "Выбрать геопозицию?", "Да", "Нет"); if (button == 0) { map.RemoveFromSuperview(); } }
void OnMapLongPress() { if (longPressGestureRecognizer.State != UIGestureRecognizerState.Began) { return; } CGPoint pixelLocation = longPressGestureRecognizer.LocationInView(NativeMapView); CLLocationCoordinate2D coordinate = NativeMapView.ConvertPoint(pixelLocation, NativeMapView); //add map annotation MKPointAnnotation annotation = new MKPointAnnotation(); annotation.Coordinate = coordinate; annotation.Title = string.Format("{0},{1}", coordinate.Latitude, coordinate.Longitude); NativeMapView.AddAnnotation(annotation); annotationsList.Add(annotation); }
// Scale and rotation transforms are applied relative to the layer's anchor point. // This method moves a UIGestureRecognizer's view anchor point between the user's fingers void AdjustAnchorPointForGestureRecognizer (UIGestureRecognizer gestureRecognizer) { if (gestureRecognizer.State == UIGestureRecognizerState.Began) { var image = gestureRecognizer.View; var locationInView = gestureRecognizer.LocationInView (image); var locationInSuperview = gestureRecognizer.LocationInView (image.Superview); image.Layer.AnchorPoint = new PointF (locationInView.X / image.Bounds.Size.Width, locationInView.Y / image.Bounds.Size.Height); image.Center = locationInSuperview; } }
/// <summary> /// Gets called when the Map is clicked. /// </summary> /// <param name="sender">Sender who fired the event.</param> private void MapTapped(UIGestureRecognizer sender) { CGPoint pointInView = sender.LocationInView(this.mapView); CLLocationCoordinate2D touchCoordinates = this.mapView.ConvertPoint(pointInView, this.mapView); FieldHelper.Instance.MapTappedEvent(new Position(touchCoordinates.Latitude, touchCoordinates.Longitude), ZoomLevel(this.mapView)); }
void EditTagFrame(UIGestureRecognizer gestureRecognizer) { Console.WriteLine ("edittagframe triggered"); if (mylock == false) { Console.WriteLine ("mutex aquired"); mylock = true; point = gestureRecognizer.LocationInView (this.blend); // Console.WriteLine ("presspoint:" + point); // PointF center = scrollView.Center; // Console.WriteLine("center:"+scrollView.Center); // float scale = scrollView.ZoomScale; // PointF con = new PointF (scrollView.ContentOffset.X / scale, scrollView.ContentOffset.Y / scale); // PointF con = new PointF (scrollView.ContentOffset.X, scrollView.ContentOffset.Y); // Console.WriteLine ("con:" + con); // PointF guess = new PointF (con.X + point.X, con.Y + point.Y); // Console.WriteLine ("guess:" + guess); Rects = new List<RectangleF> (); Tags = AppDelegate.dao.GetTagsByGalleryObjectID (go.ID); for (int i = 0; i < Tags.Count; i++) { TagUtility tu = new TagUtility (Tags [i]); Rects.Add (tu.FetchAsRectangleF ()); } for (int j = 0; j < Rects.Count; j++) { if (Rects [j].Contains (point)) { // if (finds.Exists (x => x.ID == Tags [j].ID)) { // Console.WriteLine ("pushing:" + Tags [j]); // finds.Remove (Tags [j]); tds = new TagDetailScreen (Tags [j],this); found = true; // tds.backpush += (object sender, BackClickedEventArgs e) => { // Console.WriteLine("mutex released"); // mylock = false; // }; this.NavigationController.PushViewController(tds, true); //this.NavigationController.PushViewController (tds, false); break; // } else { // Console.WriteLine ("adder:" + Tags [j]); // Console.WriteLine ("finds:" + finds.Count); // finds.Add (Tags [j]); // break; // } } } if (!found) { Console.WriteLine ("releasing mutex"); mylock = false; } } }
void HandleTap(UIGestureRecognizer gestureRecognize) { // retrieve the SCNView var scnView = (SCNView)View; // check what nodes are tapped CGPoint p = gestureRecognize.LocationInView (scnView); SCNHitTestResult[] hitResults = scnView.HitTest (p, (SCNHitTestOptions)null); // check that we clicked on at least one object if (hitResults.Length > 0) { // retrieved the first clicked object SCNHitTestResult result = hitResults[0]; // get its material SCNMaterial material = result.Node.Geometry.FirstMaterial; // highlight it SCNTransaction.Begin (); SCNTransaction.AnimationDuration = 0.5f; // on completion - unhighlight SCNTransaction.SetCompletionBlock(() => { SCNTransaction.Begin (); SCNTransaction.AnimationDuration = 0.5f; material.Emission.Contents = UIColor.Black; SCNTransaction.Commit (); }); material.Emission.Contents = UIColor.Red; SCNTransaction.Commit (); } }
void OnFocusAndExposeClicked (UIGestureRecognizer gestureRecognizer) { CGPoint devicePoint = ((AVCaptureVideoPreviewLayer)PreviewView.Layer).CaptureDevicePointOfInterestForPoint (gestureRecognizer.LocationInView (gestureRecognizer.View)); SetFocusAndMode (VideoDevice.FocusMode, VideoDevice.ExposureMode, devicePoint, true); }
public void HandleTouch (UIGestureRecognizer gestureRecognizer) { CGPoint p = gestureRecognizer.LocationInView (View); HandleTap (p); }
private void doubleTapEvent(UIGestureRecognizer sender) { // Disable gestures on preview mode if (mParent.ShouldDisplayFilledCells) return; if (sender.NumberOfTouches > 0) { PointF touchLocation = sender.LocationInView (this); Cell cell = getCellFromViewCoordinates (touchLocation); mParent.RemovePath (cell); } }
void FocusAndExposeTap (UIGestureRecognizer gestureRecognizer) { var location = gestureRecognizer.LocationInView (gestureRecognizer.View); CGPoint devicePoint = PreviewView.VideoPreviewLayer.CaptureDevicePointOfInterestForPoint (location); UpdateDeviceFocus (AVCaptureFocusMode.AutoFocus, AVCaptureExposureMode.AutoExpose, devicePoint, true); }
void AdjustAnchorPointForGestureRecognizer (UIGestureRecognizer gestureRecognizer) { if (gestureRecognizer.State == UIGestureRecognizerState.Began) { UIView piece = gestureRecognizer.View; PointF locationInView = gestureRecognizer.LocationInView (piece); PointF locationInSuperview = gestureRecognizer.LocationInView (piece.Superview); piece.Layer.AnchorPoint = new PointF (locationInView.X / piece.Bounds.Size.Width, locationInView.Y / piece.Bounds.Size.Height); piece.Center = locationInSuperview; } }
partial void handleTap (UIGestureRecognizer recognizer) { CGPoint tapPoint = recognizer.LocationInView (previewView); focus (tapPoint); expose (tapPoint); }
public bool ShouldRecognizeSimultaneously (UIGestureRecognizer gestureRecognizer, UIGestureRecognizer otherGestureRecognizer) { // Allow multiple gesture recognizers to be recognized simultaneously if and only if the touch location is not within the touch threshold. if (gestureRecognizer == resizeRegionOfInterestGestureRecognizer) { var touchLocation = gestureRecognizer.LocationInView (gestureRecognizer.View); var closestCorner = CornerOfRect (RegionOfInterest, touchLocation); return closestCorner == ControlCorner.None; } return false; }