void HandleRotation(UIRotationGestureRecognizer gesture) { // Save the Rotation value this.rotation = gesture.Rotation; // and call UpdateTransform UpdateTransform(); }
void HeadingChanged(UIRotationGestureRecognizer gesture) { // Console.WriteLine ("Rotation changed " + gesture.Rotation); if (gesture.State == UIGestureRecognizerState.Began) { currentAngle = lastAngle; } // if (gesture.State != UIGestureRecognizerState.Ended) { // lastAngle = currentAngle + gesture.Rotation; // lastAngle = (nfloat)((double)lastAngle % (2*Math.PI)); // } if (gesture.State == UIGestureRecognizerState.Ended) { lastAngle = currentAngle + gesture.Rotation; lastAngle = (nfloat)((double)lastAngle % (2 * Math.PI)); } if (currentDirectionAnnotation != null) { var view = mapView.ViewForAnnotation(currentDirectionAnnotation); view.Transform = CGAffineTransform.MakeRotation((nfloat)currentDirectionAnnotation.CurAngle + currentAngle + gesture.Rotation); } }
public override void ViewDidLoad() { base.ViewDidLoad(); map.Frame = View.Frame; View.AddSubview(map); eventView.Frame = View.Frame; map.AddSubview(eventView); rotationView.Frame = View.Frame; eventView.AddSubview(rotationView); tile.Frame = new CGRect(10, 10, 256, 256); tile.BackgroundColor = UIColor.Clear; rotationView.AddSubview(tile); UIPanGestureRecognizer panGesture = new UIPanGestureRecognizer(PanHandler); panGesture.ShouldRecognizeSimultaneously = (recognizer, gestureRecognizer) => true; UIPinchGestureRecognizer pinchGesture = new UIPinchGestureRecognizer(PinchHandler); pinchGesture.ShouldRecognizeSimultaneously = (recognizer, gestureRecognizer) => true; UIRotationGestureRecognizer rotationGesture = new UIRotationGestureRecognizer(RotationHandler); rotationGesture.ShouldRecognizeSimultaneously = (recognizer, gestureRecognizer) => true; eventView.AddGestureRecognizer(panGesture); eventView.AddGestureRecognizer(pinchGesture); eventView.AddGestureRecognizer(rotationGesture); }
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { RectangleF rect = this.Frame; if (this.MapAllowTilt && rect.Width > 0) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { this.NotifyMovementByInvoke();; _mapViewBefore = null; } else if (rotation.State == UIGestureRecognizerState.Began) { _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; _mapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter[0], sceneCenter[1]); this.NotifyMovementByInvoke(); } } }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); sceneView.Session.Run(new ARWorldTrackingConfiguration { AutoFocusEnabled = true, LightEstimationEnabled = true, PlaneDetection = ARPlaneDetection.Horizontal, WorldAlignment = ARWorldAlignment.Gravity }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors); SphereNode sphereNode = new SphereNode(size, "world-map.jpg"); sphereNode.Position = new SCNVector3(0, 0, zPosition); sceneView.Scene.RootNode.AddChildNode(sphereNode); UITapGestureRecognizer tapGestureRecognizer = new UITapGestureRecognizer(HandleTapGesture); sceneView.AddGestureRecognizer(tapGestureRecognizer); UIPinchGestureRecognizer pinchGestureRecognizer = new UIPinchGestureRecognizer(HandlePinchGesture); sceneView.AddGestureRecognizer(pinchGestureRecognizer); UIRotationGestureRecognizer rotationGestureRecognizer = new UIRotationGestureRecognizer(HandleRotateGesture); sceneView.AddGestureRecognizer(rotationGestureRecognizer); }
public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); sceneView.Session.Run(new ARWorldTrackingConfiguration { AutoFocusEnabled = true, LightEstimationEnabled = true, WorldAlignment = ARWorldAlignment.Gravity }, ARSessionRunOptions.ResetTracking | ARSessionRunOptions.RemoveExistingAnchors); SCNScene scene = SCNScene.FromFile("moon.dae"); SCNNode node = scene.RootNode; node.Position = new SCNVector3(0, 0, -25f); sceneView.Scene.RootNode.AddChildNode(node); UITapGestureRecognizer tapGestureRecognizer = new UITapGestureRecognizer(HandleTapGesture); sceneView.AddGestureRecognizer(tapGestureRecognizer); UIPinchGestureRecognizer pinchGestureRecognizer = new UIPinchGestureRecognizer(HandlePinchGesture); sceneView.AddGestureRecognizer(pinchGestureRecognizer); UIRotationGestureRecognizer rotationGestureRecognizer = new UIRotationGestureRecognizer(HandleRotateGesture); sceneView.AddGestureRecognizer(rotationGestureRecognizer); }
protected override void OnElementChanged(ElementChangedEventArgs <LRMasterDetailPage> e) { base.OnElementChanged(e); longPressGestureRecognizer = new UILongPressGestureRecognizer(() => Console.WriteLine("Long Press")); pinchGestureRecognizer = new UIPinchGestureRecognizer(() => Console.WriteLine("Pinch")); //panGestureRecognizer = new UIPanGestureRecognizer (() => Console.WriteLine ("Pan")); swipeRightGestureRecognizer = new UISwipeGestureRecognizer(() => UpdateRight()) { Direction = UISwipeGestureRecognizerDirection.Right }; swipeLeftGestureRecognizer = new UISwipeGestureRecognizer(() => UpdateLeft()) { Direction = UISwipeGestureRecognizerDirection.Left }; rotationGestureRecognizer = new UIRotationGestureRecognizer(() => Console.WriteLine("Rotation")); if (e.NewElement == null) { if (longPressGestureRecognizer != null) { this.RemoveGestureRecognizer(longPressGestureRecognizer); } if (pinchGestureRecognizer != null) { this.RemoveGestureRecognizer(pinchGestureRecognizer); } /* * if (panGestureRecognizer != null) { * this.RemoveGestureRecognizer (panGestureRecognizer); * } */ if (swipeRightGestureRecognizer != null) { this.RemoveGestureRecognizer(swipeRightGestureRecognizer); } if (swipeLeftGestureRecognizer != null) { this.RemoveGestureRecognizer(swipeLeftGestureRecognizer); } if (rotationGestureRecognizer != null) { this.RemoveGestureRecognizer(rotationGestureRecognizer); } } if (e.OldElement == null) { this.AddGestureRecognizer(longPressGestureRecognizer); this.AddGestureRecognizer(pinchGestureRecognizer); //this.AddGestureRecognizer (panGestureRecognizer); this.AddGestureRecognizer(swipeRightGestureRecognizer); this.AddGestureRecognizer(swipeLeftGestureRecognizer); this.AddGestureRecognizer(rotationGestureRecognizer); } }
public override void ViewDidLoad() { base.ViewDidLoad(); nfloat r = 0; nfloat dx = 0; nfloat dy = 0; using (var image = UIImage.FromFile("monkey.png")) { imageView = new UIImageView(image) { Frame = new CGRect(new CGPoint(0, 0), image.Size) }; imageView.UserInteractionEnabled = true; View.AddSubview(imageView); } rotateGesture = new UIRotationGestureRecognizer((() => { if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) { imageView.Transform = CGAffineTransform.MakeRotation(rotateGesture.Rotation + r); } else if (rotateGesture.State == UIGestureRecognizerState.Ended) { r += rotateGesture.Rotation; } })); panGesture = new UIPanGestureRecognizer(() => { if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1)) { var p0 = panGesture.LocationInView(View); if (dx == 0) { dx = p0.X - imageView.Center.X; } if (dy == 0) { dy = p0.Y - imageView.Center.Y; } var p1 = new CGPoint(p0.X - dx, p0.Y - dy); imageView.Center = p1; } else if (panGesture.State == UIGestureRecognizerState.Ended) { dx = 0; dy = 0; } }); imageView.AddGestureRecognizer(panGesture); imageView.AddGestureRecognizer(rotateGesture); View.BackgroundColor = UIColor.White; }
public override void ViewDidLoad() { base.ViewDidLoad(); image.UserInteractionEnabled = true; // var GestoToque = new UITapGestureRecognizer(Tocando); //Se aplican los gestos a la imagen image.AddGestureRecognizer(GestoToque); GestoMover = new UIPanGestureRecognizer(() => { if ((GestoMover.State == UIGestureRecognizerState.Began || //Validar el estado del gesto GestoMover.State == UIGestureRecognizerState.Changed) && (GestoMover.NumberOfTouches == 1)) { var P0 = GestoMover.LocationInView(View); //Gesto en toda la pantalla. if (coordenadasX == 0) { coordenadasX = P0.X - image.Center.X; } if (coordenadasY == 0) { coordenadasY = P0.Y - image.Center.Y; } var P1 = new CGPoint(P0.X - coordenadasX, P0.Y - coordenadasY); image.Center = P1; } else { coordenadasX = 0; coordenadasY = 0; } }); GestoRotar = new UIRotationGestureRecognizer(() => { if ((GestoRotar.State == UIGestureRecognizerState.Began || //Validar el estado del gesto GestoRotar.State == UIGestureRecognizerState.Changed) && (GestoRotar.NumberOfTouches == 2)) //el gesto de rotar se hace con dos toques. { image.Transform = CGAffineTransform.MakeRotation(GestoRotar.Rotation + rotacion); //Se vuelve a verificar el estado, para validar en donde se quedo. } else if (GestoRotar.State == UIGestureRecognizerState.Ended) { rotacion = GestoRotar.Rotation; //Se obtinen los valores de rotación. } }); //Se aplican los gestos a la imagen image.AddGestureRecognizer(GestoMover); image.AddGestureRecognizer(GestoRotar); }
protected override void OnElementChanged(ElementChangedEventArgs <Frame> e) { base.OnElementChanged(e); if (e.NewElement == null) { RemoveGestureRecognizer(); return; } var gestureView = e.NewElement as GestureAwareContentView; _longPressGestureRecognizer = new UILongPressGestureRecognizer( sender => { var offset = sender.LocationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.LongPress, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _pinchGestureRecognizer = new UIPinchGestureRecognizer( sender => { var scale = sender.Scale; GestureUtil.ExecuteCommand(gestureView.Pinch, new GestureScale(sender.State.ToGestureState(), scale)); }); _panGestureRecognizer = new UIPanGestureRecognizer( sender => { var offset = sender.TranslationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.Pan, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _swipeGestureRecognizer = new UISwipeGestureRecognizer( sender => { var offset = sender.LocationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.Swipe, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _rotationGestureRecognizer = new UIRotationGestureRecognizer( sender => { GestureUtil.ExecuteCommand(gestureView.Rotate); }); AddGestureRecognizer(_longPressGestureRecognizer); AddGestureRecognizer(_pinchGestureRecognizer); AddGestureRecognizer(_panGestureRecognizer); AddGestureRecognizer(_swipeGestureRecognizer); AddGestureRecognizer(_rotationGestureRecognizer); }
// Rotates the image by the current rotation void RotateImage(UIRotationGestureRecognizer gestureRecognizer) { AdjustAnchorPointForGestureRecognizer(gestureRecognizer); if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) { gestureRecognizer.View.Transform *= CGAffineTransform.MakeRotation(gestureRecognizer.Rotation); // Reset the gesture recognizer's rotation - the next callback will get a delta from the current rotation. gestureRecognizer.Rotation = 0; } }
private void AddRotationAndPinchGestureRecognizers() { rotationGestureRecognizer = new UIRotationGestureRecognizer(RotateSquare); pinchGestureRecognizer = new UIPinchGestureRecognizer(ScaleSquare); rotationGestureRecognizer.ShouldRecognizeSimultaneously += GestureRecognizer_ShouldRecognizeSimultaneously; pinchGestureRecognizer.ShouldRecognizeSimultaneously += GestureRecognizer_ShouldRecognizeSimultaneously; View.AddGestureRecognizer(pinchGestureRecognizer); View.AddGestureRecognizer(rotationGestureRecognizer); }
private void RotationHandler(UIRotationGestureRecognizer gesture) { if (gesture.State == UIGestureRecognizerState.Changed) { Stopwatch sw = Stopwatch.StartNew(); rotationView.Transform = CGAffineTransform.Rotate(rotationView.Transform, gesture.Rotation); gesture.Rotation = 0; sw.Stop(); Console.WriteLine("Rotating: " + sw.ElapsedMilliseconds); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. Imagen.UserInteractionEnabled = true; var GestoToque = new UITapGestureRecognizer(Tocando); Imagen.AddGestureRecognizer(GestoToque); GestoMover = new UIPanGestureRecognizer(() => { if ((GestoMover.State == UIGestureRecognizerState.Began || GestoMover.State == UIGestureRecognizerState.Changed) && (GestoMover.NumberOfTouches == 1)) { var p0 = GestoMover.LocationInView(View); if (coordenadaX == 0) { coordenadaX = p0.X - Imagen.Center.X; } if (coordenadaY == 0) { coordenadaY = p0.Y - Imagen.Center.Y; } var p1 = new CGPoint(p0.X - coordenadaX, p0.Y - coordenadaY); Imagen.Center = p1; } else { coordenadaX = 0; coordenadaY = 0; } }); GestoRotar = new UIRotationGestureRecognizer(() => { if ((GestoRotar.State == UIGestureRecognizerState.Began || GestoRotar.State == UIGestureRecognizerState.Changed) && (GestoRotar.NumberOfTouches == 2)) { Imagen.Transform = CGAffineTransform.MakeRotation(GestoRotar.Rotation + rotacion); } else if (GestoRotar.State == UIGestureRecognizerState.Ended) { rotacion = GestoRotar.Rotation; } }); Imagen.AddGestureRecognizer(GestoMover); Imagen.AddGestureRecognizer(GestoRotar); }
public void OnRotationGesture(UIRotationGestureRecognizer sender) { var location0 = sender.LocationOfTouch(0, sender.View); var position0 = GetOffsetPosition(new Vector2(location0.X, location0.Y), true); var location1 = sender.LocationOfTouch(1, sender.View); var position1 = GetOffsetPosition(new Vector2(location1.X, location1.Y), true); TouchPanel.GestureList.Enqueue(new GestureSample( GestureType.Rotation, new TimeSpan(DateTime.Now.Ticks), position0, position1, Vector2.Zero, Vector2.Zero)); }
public PlayGroundView() { pinchGesture = new UIPinchGestureRecognizer (Scale); this.AddGestureRecognizer (pinchGesture); var rotationGesture = new UIRotationGestureRecognizer (Rotate); this.AddGestureRecognizer (rotationGesture); var panGesture = new UIPanGestureRecognizer (Move); this.AddGestureRecognizer (panGesture); this.BackgroundColor = UIColor.DarkGray; }
public PlayGroundView() { pinchGesture = new UIPinchGestureRecognizer(Scale); this.AddGestureRecognizer(pinchGesture); var rotationGesture = new UIRotationGestureRecognizer(Rotate); this.AddGestureRecognizer(rotationGesture); var panGesture = new UIPanGestureRecognizer(Move); this.AddGestureRecognizer(panGesture); this.BackgroundColor = UIColor.DarkGray; }
void HandleRotateGesture(UIRotationGestureRecognizer 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; zAngle += (float)(-sender.Rotation); node.EulerAngles = new SCNVector3(node.EulerAngles.X, node.EulerAngles.Y, zAngle); } }
private void CreateRotationGestureRecognizer() { rotateGesture = new UIRotationGestureRecognizer(() => { if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) { Transform = CGAffineTransform.MakeRotation(rotateGesture.Rotation + r); } else if (rotateGesture.State == UIGestureRecognizerState.Ended) { r += rotateGesture.Rotation; } }); }
void initView() { UserInteractionEnabled = true; MultipleTouchEnabled = true; scaleTransform = CGAffineTransform.MakeIdentity(); rotateTransform = CGAffineTransform.MakeIdentity(); panTransform = CGAffineTransform.MakeIdentity(); initialIndex = 0; allowSingleTapSwitch = true; UIPinchGestureRecognizer pinchRecognizer = new UIPinchGestureRecognizer(handlePinchPanRotate); pinchRecognizer.CancelsTouchesInView = false; pinchRecognizer.DelaysTouchesBegan = false; pinchRecognizer.DelaysTouchesEnded = false; AddGestureRecognizer(pinchRecognizer); UIRotationGestureRecognizer rotationRecognizer = new UIRotationGestureRecognizer(handlePinchPanRotate); rotationRecognizer.CancelsTouchesInView = false; rotationRecognizer.DelaysTouchesBegan = false; rotationRecognizer.DelaysTouchesEnded = false; AddGestureRecognizer(rotationRecognizer); panRecognizer = new UIPanGestureRecognizer(handlePinchPanRotate); panRecognizer.CancelsTouchesInView = false; panRecognizer.DelaysTouchesBegan = false; panRecognizer.DelaysTouchesEnded = false; panRecognizer.MinimumNumberOfTouches = 2; panRecognizer.MaximumNumberOfTouches = 2; AddGestureRecognizer(panRecognizer); tapRecognizer = new UITapGestureRecognizer(handleTap); tapRecognizer.CancelsTouchesInView = false; tapRecognizer.DelaysTouchesBegan = false; tapRecognizer.DelaysTouchesEnded = false; AddGestureRecognizer(tapRecognizer); /** DELEGATE METHODS **/ pinchRecognizer.WeakDelegate = this; rotationRecognizer.WeakDelegate = this; panRecognizer.WeakDelegate = this; tapRecognizer.WeakDelegate = this; shouldContinue = true; }
public override void ViewDidLoad () { base.ViewDidLoad (); nfloat r = 0; nfloat dx = 0; nfloat dy = 0; using (var image = UIImage.FromFile ("monkey.png")) { imageView = new UIImageView (image){Frame = new CGRect (new CGPoint(0,0), image.Size)}; imageView.UserInteractionEnabled = true; View.AddSubview (imageView); } rotateGesture = new UIRotationGestureRecognizer ((() => { if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) { imageView.Transform = CGAffineTransform.MakeRotation (rotateGesture.Rotation + r); } else if (rotateGesture.State == UIGestureRecognizerState.Ended) { r += rotateGesture.Rotation; } })); panGesture = new UIPanGestureRecognizer (() => { if ((panGesture.State == UIGestureRecognizerState.Began || panGesture.State == UIGestureRecognizerState.Changed) && (panGesture.NumberOfTouches == 1)) { var p0 = panGesture.LocationInView (View); if (dx == 0) dx = p0.X - imageView.Center.X; if (dy == 0) dy = p0.Y - imageView.Center.Y; var p1 = new CGPoint (p0.X - dx, p0.Y - dy); imageView.Center = p1; } else if (panGesture.State == UIGestureRecognizerState.Ended) { dx = 0; dy = 0; } }); imageView.AddGestureRecognizer (panGesture); imageView.AddGestureRecognizer (rotateGesture); View.BackgroundColor = UIColor.White; }
public override void ViewDidLoad() { base.ViewDidLoad(); Imagen.UserInteractionEnabled = true; var GestoToque = new UITapGestureRecognizer(Tocando); Gestomover = new UIPanGestureRecognizer(() => { if ((Gestomover.State == UIGestureRecognizerState.Began || Gestomover.State == UIGestureRecognizerState.Changed) && (Gestomover.NumberOfTouches == 1)) { var p0 = Gestomover.LocationInView(View); if (CoordenadaX == 0) { CoordenadaX = p0.X - Imagen.Center.X; } if (CoordenadaY == 0) { CoordenadaY = p0.Y - Imagen.Center.Y; } var p1 = new CGPoint(p0.X - CoordenadaX, p0.Y - CoordenadaY); Imagen.Center = p1; } else { CoordenadaX = 0; CoordenadaY = 0; } }); GestoRotar = new UIRotationGestureRecognizer(() => { if ((GestoRotar.State == UIGestureRecognizerState.Began || GestoRotar.State == UIGestureRecognizerState.Changed) && (GestoRotar.NumberOfTouches == 2)) { Imagen.Transform = CGAffineTransform.MakeRotation(GestoRotar.Rotation + Rotation); } else if (GestoRotar.State == UIGestureRecognizerState.Ended) { Rotation = GestoRotar.Rotation; } }); Imagen.AddGestureRecognizer(Gestomover); Imagen.AddGestureRecognizer(GestoRotar); Imagen.AddGestureRecognizer(GestoToque); }
protected override void OnElementChanged(ElementChangedEventArgs <Image> e) { base.OnElementChanged(e); longPressGestureRecognizer = new UILongPressGestureRecognizer(() => Console.WriteLine("Long Press")); pinchGestureRecognizer = new UIPinchGestureRecognizer(() => Console.WriteLine("Pinch")); panGestureRecognizer = new UIPanGestureRecognizer(() => Console.WriteLine("Pan")); swipeGestureRecognizer = new UISwipeGestureRecognizer(() => Console.WriteLine("Swipe")); rotationGestureRecognizer = new UIRotationGestureRecognizer(() => Console.WriteLine("Rotation")); if (e.NewElement == null) { if (longPressGestureRecognizer != null) { RemoveGestureRecognizer(longPressGestureRecognizer); } if (pinchGestureRecognizer != null) { RemoveGestureRecognizer(pinchGestureRecognizer); } if (panGestureRecognizer != null) { RemoveGestureRecognizer(panGestureRecognizer); } if (swipeGestureRecognizer != null) { RemoveGestureRecognizer(swipeGestureRecognizer); } if (rotationGestureRecognizer != null) { RemoveGestureRecognizer(rotationGestureRecognizer); } } if (e.OldElement == null) { AddGestureRecognizer(longPressGestureRecognizer); AddGestureRecognizer(pinchGestureRecognizer); AddGestureRecognizer(panGestureRecognizer); AddGestureRecognizer(swipeGestureRecognizer); AddGestureRecognizer(rotationGestureRecognizer); } }
UIRotationGestureRecognizer rotationGestureRecognizer; protected override void OnElementChanged(ElementChangedEventArgs <Label> e) { base.OnElementChanged(e); longPressGestureRecognizer = new UILongPressGestureRecognizer(() => Console.WriteLine("擴充手勢事件 : ----->> Long Press")); pinchGestureRecognizer = new UIPinchGestureRecognizer(() => Console.WriteLine("擴充手勢事件 : ----->> Pinch")); panGestureRecognizer = new UIPanGestureRecognizer(() => Console.WriteLine("擴充手勢事件 : ----->> Pan")); swipeGestureRecognizer = new UISwipeGestureRecognizer(() => Console.WriteLine("擴充手勢事件 : ----->> Swipe")); rotationGestureRecognizer = new UIRotationGestureRecognizer(() => Console.WriteLine("擴充手勢事件 : ----->> Rotation")); if (e.NewElement == null) { if (longPressGestureRecognizer != null) { this.RemoveGestureRecognizer(longPressGestureRecognizer); } if (pinchGestureRecognizer != null) { this.RemoveGestureRecognizer(pinchGestureRecognizer); } if (panGestureRecognizer != null) { this.RemoveGestureRecognizer(panGestureRecognizer); } if (swipeGestureRecognizer != null) { this.RemoveGestureRecognizer(swipeGestureRecognizer); } if (rotationGestureRecognizer != null) { this.RemoveGestureRecognizer(rotationGestureRecognizer); } } if (e.OldElement == null) { this.AddGestureRecognizer(longPressGestureRecognizer); this.AddGestureRecognizer(pinchGestureRecognizer); this.AddGestureRecognizer(panGestureRecognizer); this.AddGestureRecognizer(swipeGestureRecognizer); this.AddGestureRecognizer(rotationGestureRecognizer); } }
void Rotate(UIRotationGestureRecognizer gesture) { if (CurrentMonkey == null) { return; } if (gesture.State == UIGestureRecognizerState.Ended) { lastRotation = 0; CurrentMonkey.UpdateMonkey(0, this.Bounds); Parent.UpdateMonkey(CurrentMonkey.Monkey); return; } var rotation = 0 - (lastRotation - gesture.Rotation); var transform = CurrentMonkey.Transform; transform.Rotate(rotation); CurrentMonkey.Transform = transform; lastRotation = gesture.Rotation; }
private void RotateSquare(UIRotationGestureRecognizer sender) { //UpdateSquareTransform(new CGPoint(), sender.Rotation, 1.0f); if (sender.State == UIGestureRecognizerState.Changed) { if (pinchGestureRecognizer.State == UIGestureRecognizerState.Changed) { UpdateSquareTransform(new CGPoint(), sender.Rotation, pinchGestureRecognizer.Scale); } else { UpdateSquareTransform(new CGPoint(), sender.Rotation, 1.0f); } } if (sender.State == UIGestureRecognizerState.Ended) { lastRotation += sender.Rotation; } }
private void RemoveGestureRecognizer() { if (_longPressGestureRecognizer != null) { RemoveGestureRecognizer(_longPressGestureRecognizer); _longPressGestureRecognizer.Dispose(); _longPressGestureRecognizer = null; } if (_pinchGestureRecognizer != null) { RemoveGestureRecognizer(_pinchGestureRecognizer); _pinchGestureRecognizer.Dispose(); _pinchGestureRecognizer = null; } if (_panGestureRecognizer != null) { RemoveGestureRecognizer(_panGestureRecognizer); _panGestureRecognizer.Dispose(); _panGestureRecognizer = null; } if (_swipeGestureRecognizer != null) { RemoveGestureRecognizer(_swipeGestureRecognizer); _swipeGestureRecognizer.Dispose(); _swipeGestureRecognizer = null; } if (_rotationGestureRecognizer != null) { RemoveGestureRecognizer(_rotationGestureRecognizer); _rotationGestureRecognizer.Dispose(); _rotationGestureRecognizer = null; } }
// Add gesture recognizers to one of our images void AddGestureRecognizersToImage(UIImageView image) { image.UserInteractionEnabled = true; var rotationGesture = new UIRotationGestureRecognizer(RotateImage); image.AddGestureRecognizer(rotationGesture); var pinchGesture = new UIPinchGestureRecognizer(ScaleImage); pinchGesture.Delegate = new GestureDelegate(this); image.AddGestureRecognizer(pinchGesture); var panGesture = new UIPanGestureRecognizer(PanImage); panGesture.MaximumNumberOfTouches = 2; panGesture.Delegate = new GestureDelegate(this); image.AddGestureRecognizer(panGesture); var longPressGesture = new UILongPressGestureRecognizer(ShowResetMenu); image.AddGestureRecognizer(longPressGesture); }
public override void ViewDidLoad() { base.ViewDidLoad(); var rotationGesture = new UIRotationGestureRecognizer(HandleRotation); this.View.AddGestureRecognizer(rotationGesture); var pinchGesture = new UIPinchGestureRecognizer(HandlePinch); this.View.AddGestureRecognizer(pinchGesture); var panGesture = new UIPanGestureRecognizer(HandlePan); this.View.AddGestureRecognizer(panGesture); // Set the ShouldRecognizeSimultaneously delegate for both gestures // to the ShouldRecognizeSimultaneously method we just created // run the app rotationGesture.ShouldRecognizeSimultaneously = ShouldRecognizeSimultaneously; pinchGesture.ShouldRecognizeSimultaneously = ShouldRecognizeSimultaneously; panGesture.ShouldRecognizeSimultaneously = ShouldRecognizeSimultaneously; }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. Image.UserInteractionEnabled = true; RotacionGesture = new UIRotationGestureRecognizer(RotateImage); Image.AddGestureRecognizer(RotacionGesture); LongGesture = new UILongPressGestureRecognizer(ShowResetMenu); Image.AddGestureRecognizer(LongGesture); PinchGesture = new UIPinchGestureRecognizer(ScaleImage); PinchGesture.Delegate = new GestureDelegate(this); Image.AddGestureRecognizer(PinchGesture); PanGesture = new UIPanGestureRecognizer(PanImage); PanGesture.MaximumNumberOfTouches = 2; PanGesture.Delegate = new GestureDelegate(this); Image.AddGestureRecognizer(PanGesture); }
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { //RectangleF2D rect = _rect; RectangleF rect = this.Frame; if (rect.Width > 0) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; _mapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter [0], sceneCenter [1]); this.Change(true); _mapViewBefore = null; } else if (rotation.State == UIGestureRecognizerState.Began) { _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; _mapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter [0], sceneCenter [1]); this.InvokeOnMainThread(InvalidateMap); } } }
protected override void OnElementChanged (ElementChangedEventArgs<Label> e) { base.OnElementChanged (e); longPressGestureRecognizer = new UILongPressGestureRecognizer (() => Console.WriteLine ("Long Press")); pinchGestureRecognizer = new UIPinchGestureRecognizer (() => Console.WriteLine ("Pinch")); panGestureRecognizer = new UIPanGestureRecognizer (() => Console.WriteLine ("Pan")); swipeGestureRecognizer = new UISwipeGestureRecognizer (() => Console.WriteLine ("Swipe")); rotationGestureRecognizer = new UIRotationGestureRecognizer (() => Console.WriteLine ("Rotation")); if (e.NewElement == null) { if (longPressGestureRecognizer != null) { this.RemoveGestureRecognizer (longPressGestureRecognizer); } if (pinchGestureRecognizer != null) { this.RemoveGestureRecognizer (pinchGestureRecognizer); } if (panGestureRecognizer != null) { this.RemoveGestureRecognizer (panGestureRecognizer); } if (swipeGestureRecognizer != null) { this.RemoveGestureRecognizer (swipeGestureRecognizer); } if (rotationGestureRecognizer != null) { this.RemoveGestureRecognizer (rotationGestureRecognizer); } } if (e.OldElement == null) { this.AddGestureRecognizer (longPressGestureRecognizer); this.AddGestureRecognizer (pinchGestureRecognizer); this.AddGestureRecognizer (panGestureRecognizer); this.AddGestureRecognizer (swipeGestureRecognizer); this.AddGestureRecognizer (rotationGestureRecognizer); } }
private void RemoveGestureRecognizer() { if (_longPressGestureRecognizer != null) { RemoveGestureRecognizer (_longPressGestureRecognizer); _longPressGestureRecognizer.Dispose (); _longPressGestureRecognizer = null; } if (_pinchGestureRecognizer != null) { RemoveGestureRecognizer (_pinchGestureRecognizer); _pinchGestureRecognizer.Dispose (); _pinchGestureRecognizer = null; } if (_panGestureRecognizer != null) { RemoveGestureRecognizer (_panGestureRecognizer); _panGestureRecognizer.Dispose (); _panGestureRecognizer = null; } if (_swipeGestureRecognizer != null) { RemoveGestureRecognizer (_swipeGestureRecognizer); _swipeGestureRecognizer.Dispose (); _swipeGestureRecognizer = null; } if (_rotationGestureRecognizer != null) { RemoveGestureRecognizer (_rotationGestureRecognizer); _rotationGestureRecognizer.Dispose (); _rotationGestureRecognizer = null; } }
public iOS_RotateGestureEventArgs(RotationGestureRecognizer gestureRecognizer, UIRotationGestureRecognizer platformGestureRecognizer) { this.gestureRecognizer = gestureRecognizer; this.platformGestureRecognizer = platformGestureRecognizer; }
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { //RectangleF2D rect = _rect; RectangleF rect = this.Frame; if (this.MapAllowTilt && rect.Width > 0) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { // View2D rotatedView = _mapViewBefore.RotateAroundCenter ((Radian)rotation.Rotation); // _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; // PointF2D sceneCenter = rotatedView.Rectangle.Center; // _mapCenter = this.Map.Projection.ToGeoCoordinates ( // sceneCenter [0], sceneCenter [1]); this.Change(true); _mapViewBefore = null; } else if (rotation.State == UIGestureRecognizerState.Began) { _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; _mapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter[0], sceneCenter[1]); this.InvokeOnMainThread(InvalidateMap); } } }
private void CreateRotationGestureRecognizer() { rotateGesture = new UIRotationGestureRecognizer(() => { if ((rotateGesture.State == UIGestureRecognizerState.Began || rotateGesture.State == UIGestureRecognizerState.Changed) && (rotateGesture.NumberOfTouches == 2)) { Transform = CGAffineTransform.MakeRotation(rotateGesture.Rotation + r); } else if (rotateGesture.State == UIGestureRecognizerState.Ended) { r += rotateGesture.Rotation; } }); }
public void RotationGestureRecognizer(UIRotationGestureRecognizer sender) { var enabledGestures = TouchPanel.EnabledGestures; if ((enabledGestures & GestureType.Rotation) != 0) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Rotation, new TimeSpan(_now.Ticks), new Vector2 (sender.LocationInView (sender.View)), new Vector2 (sender.LocationInView (sender.View)), new Vector2(0,0), new Vector2(0,0))); } }
public void RotationGestureRecognizer(UIRotationGestureRecognizer sender) { // This shouldn't even exist, given it doesn't in XNA? TouchPanel.GestureList.Enqueue( new GestureSample( GestureType.Rotation, new TimeSpan(_nowUpdate.Ticks), GetOffsetPosition(new Vector2(sender.LocationOfTouch(0,sender.View)), true), GetOffsetPosition(new Vector2(sender.LocationOfTouch(1,sender.View)), true), new Vector2(sender.Rotation, sender.Velocity), // If it does, exist these 2 values are arbitrarily set to describe the rotation new Vector2(0,0) )); }
public void RotationGestureRecognizer(UIRotationGestureRecognizer sender) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Rotation, new TimeSpan(_nowUpdate.Ticks), new Vector2(sender.LocationInView(sender.View)), new Vector2(sender.LocationInView(sender.View)), new Vector2(0, 0), new Vector2(0, 0))); }
// Rotates the image by the current rotation void RotateImage (UIRotationGestureRecognizer gestureRecognizer) { AdjustAnchorPointForGestureRecognizer (gestureRecognizer); if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) { gestureRecognizer.View.Transform *= CGAffineTransform.MakeRotation (gestureRecognizer.Rotation); // Reset the gesture recognizer's rotation - the next callback will get a delta from the current rotation. gestureRecognizer.Rotation = 0; } }
private static void Register(View view, UIView uiview) { foreach (var elementsGestureRecognizer in view.GestureRecognizers) { TypeSwitch.Do(elementsGestureRecognizer, TypeSwitch.Case<XF.GestureRecognizers.TapGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UITapGestureRecognizer { NumberOfTapsRequired = gestureRecognizer.NumberOfTaps, NumberOfTouchesRequired = gestureRecognizer.NumberOfTouches, ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_TapGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }), TypeSwitch.Case<LongPressGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UILongPressGestureRecognizer { NumberOfTapsRequired = gestureRecognizer.NumberOfTaps, NumberOfTouchesRequired = gestureRecognizer.NumberOfTouches, MinimumPressDuration = gestureRecognizer.MinimumDuration, ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_LongPressGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }), TypeSwitch.Case<PanGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UIPanGestureRecognizer { MaximumNumberOfTouches = gestureRecognizer.MaximumNumberOfTouches, MinimumNumberOfTouches = gestureRecognizer.MinimumNumberOfTouches, ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_PanGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }), TypeSwitch.Case<XF.GestureRecognizers.PinchGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UIPinchGestureRecognizer { ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_PinchGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }), TypeSwitch.Case<SwipeGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UISwipeGestureRecognizer { Direction = (UISwipeGestureRecognizerDirection)gestureRecognizer.Direction, ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_SwipeGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }), TypeSwitch.Case<RotationGestureRecognizer>(gestureRecognizer => { var platformGestureRecognizer = new UIRotationGestureRecognizer { ShouldRecognizeSimultaneously = (a, b) => true }; var eventArgs = new iOS_RotateGestureEventArgs(gestureRecognizer, platformGestureRecognizer); platformGestureRecognizer.AddTarget(() => { if (gestureRecognizer.Command != null && gestureRecognizer.Command.CanExecute(gestureRecognizer.CommandParameter)) { gestureRecognizer.Command.Execute(eventArgs); } }); uiview.AddGestureRecognizer(platformGestureRecognizer); }) ); } }
public void RotationGestureRecognizer(UIRotationGestureRecognizer sender) { TouchPanel.GestureList.Enqueue(new GestureSample(GestureType.Rotation, new TimeSpan(_nowUpdate.Ticks), new Vector2 (sender.LocationInView (sender.View)), new Vector2 (sender.LocationInView (sender.View)), new Vector2(0,0), new Vector2(0,0))); }
public void OnRotationGesture (UIRotationGestureRecognizer sender) { var location0 = sender.LocationOfTouch (0, sender.View); var position0 = GetOffsetPosition (new Vector2(location0.X, location0.Y), true); var location1 = sender.LocationOfTouch (1, sender.View); var position1 = GetOffsetPosition (new Vector2(location1.X, location1.Y), true); TouchPanel.GestureList.Enqueue (new GestureSample ( GestureType.Rotation, new TimeSpan (DateTime.Now.Ticks), position0, position1, Vector2.Zero, Vector2.Zero)); }
protected override void OnElementChanged(ElementChangedEventArgs<Frame> e) { base.OnElementChanged (e); if (e.NewElement == null) { RemoveGestureRecognizer (); return; } var gestureView = e.NewElement as GestureAwareContentView; _longPressGestureRecognizer = new UILongPressGestureRecognizer ( sender => { var offset = sender.LocationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.LongPress, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _pinchGestureRecognizer = new UIPinchGestureRecognizer ( sender => { var scale = sender.Scale; GestureUtil.ExecuteCommand(gestureView.Pinch, new GestureScale(sender.State.ToGestureState(), scale)); }); _panGestureRecognizer = new UIPanGestureRecognizer ( sender => { var offset = sender.TranslationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.Pan, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _swipeGestureRecognizer = new UISwipeGestureRecognizer ( sender => { var offset = sender.LocationInView(NativeView); GestureUtil.ExecuteCommand(gestureView.Swipe, new GestureOffset(sender.State.ToGestureState(), offset.X, offset.Y)); }); _rotationGestureRecognizer = new UIRotationGestureRecognizer ( sender => { GestureUtil.ExecuteCommand (gestureView.Rotate); }); AddGestureRecognizer (_longPressGestureRecognizer); AddGestureRecognizer (_pinchGestureRecognizer); AddGestureRecognizer (_panGestureRecognizer); AddGestureRecognizer (_swipeGestureRecognizer); AddGestureRecognizer (_rotationGestureRecognizer); }
/// <summary> /// Rotate the specified rotation. /// </summary> /// <param name="rotation">Rotation.</param> private void Rotate(UIRotationGestureRecognizer rotation) { CGRect rect = this.Frame; if (this.MapAllowTilt && rect.Width > 0 && this.Map != null) { this.StopCurrentAnimation(); if (rotation.State == UIGestureRecognizerState.Ended) { this.NotifyMovementByInvoke();; _mapViewBefore = null; // raise map touched event. this.RaiseMapTouched(); this.RaiseMapTouchedUp(); } else if (rotation.State == UIGestureRecognizerState.Began) { this.RaiseMapTouchedDown(); _mapViewBefore = this.CreateView(rect); } else { //_mapViewBefore = this.CreateView (_rect); View2D rotatedView = _mapViewBefore.RotateAroundCenter((Radian)(float)rotation.Rotation); _mapTilt = (float)((Degree)rotatedView.Rectangle.Angle).Value; PointF2D sceneCenter = rotatedView.Rectangle.Center; this.MapCenter = this.Map.Projection.ToGeoCoordinates( sceneCenter[0], sceneCenter[1]); this.NotifyMovementByInvoke(); // raise map move event. this.RaiseMapMove(); } } }
// Add gesture recognizers to one of our images void AddGestureRecognizersToImage (UIImageView image) { image.UserInteractionEnabled = true; var rotationGesture = new UIRotationGestureRecognizer (RotateImage); image.AddGestureRecognizer (rotationGesture); var pinchGesture = new UIPinchGestureRecognizer (ScaleImage); pinchGesture.Delegate = new GestureDelegate (this); image.AddGestureRecognizer (pinchGesture); var panGesture = new UIPanGestureRecognizer (PanImage); panGesture.MaximumNumberOfTouches = 2; panGesture.Delegate = new GestureDelegate (this); image.AddGestureRecognizer (panGesture); var longPressGesture = new UILongPressGestureRecognizer (ShowResetMenu); image.AddGestureRecognizer (longPressGesture); }
/// <summary> /// Initialize the specified defaultMapCenter, defaultMap, defaultMapTilt and defaultMapZoom. /// </summary> /// <param name="defaultMapCenter">Default map center.</param> /// <param name="defaultMap">Default map.</param> /// <param name="defaultMapTilt">Default map tilt.</param> /// <param name="defaultMapZoom">Default map zoom.</param> public void Initialize(GeoCoordinate defaultMapCenter, Map defaultMap, Degree defaultMapTilt, float defaultMapZoom) { // register the default listener. (this as IInvalidatableMapSurface).RegisterListener(new DefaultTrigger(this)); // enable all interactions by default. this.MapAllowPan = true; this.MapAllowTilt = true; this.MapAllowZoom = true; // set clip to bounds to prevent objects from being rendered/show outside of the mapview. this.ClipsToBounds = true; MapCenter = defaultMapCenter; _map = defaultMap; MapTilt = defaultMapTilt; MapZoom = defaultMapZoom; _map.MapChanged += MapChanged; _doubleTapAnimator = new MapViewAnimator(this); this.BackgroundColor = UIColor.White; this.UserInteractionEnabled = true; if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0)) { var panGesture = new UIPanGestureRecognizer(Pan); panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! panGesture.ShouldRequireFailureOf = (a, b) => { return false; }; panGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer(panGesture); var pinchGesture = new UIPinchGestureRecognizer(Pinch); pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! pinchGesture.ShouldRequireFailureOf = (a, b) => { return false; }; pinchGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer(pinchGesture); var rotationGesture = new UIRotationGestureRecognizer(Rotate); rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; // TODO: workaround for xamarin bug, remove later! rotationGesture.ShouldRequireFailureOf = (a, b) => { return false; }; rotationGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; this.AddGestureRecognizer(rotationGesture); var singleTapGesture = new UITapGestureRecognizer(SingleTap); singleTapGesture.NumberOfTapsRequired = 1; // TODO: workaround for xamarin bug, remove later! // singleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; }; // singleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; var doubleTapGesture = new UITapGestureRecognizer(DoubleTap); doubleTapGesture.NumberOfTapsRequired = 2; // TODO: workaround for xamarin bug, remove later! // doubleTapGesture.ShouldRequireFailureOf = (a, b) => { return false; }; // doubleTapGesture.ShouldBeRequiredToFailBy = (a, b) => { return false; }; //singleTapGesture.RequireGestureRecognizerToFail (doubleTapGesture); this.AddGestureRecognizer(singleTapGesture); this.AddGestureRecognizer(doubleTapGesture); } else { var panGesture = new UIPanGestureRecognizer(Pan); panGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer(panGesture); var pinchGesture = new UIPinchGestureRecognizer(Pinch); pinchGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer(pinchGesture); var rotationGesture = new UIRotationGestureRecognizer(Rotate); rotationGesture.ShouldRecognizeSimultaneously += (UIGestureRecognizer r, UIGestureRecognizer other) => { return true; }; this.AddGestureRecognizer(rotationGesture); var singleTapGesture = new UITapGestureRecognizer(SingleTap); singleTapGesture.NumberOfTapsRequired = 1; //singleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle; //singleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslySingle; var doubleTapGesture = new UITapGestureRecognizer(DoubleTap); doubleTapGesture.NumberOfTapsRequired = 2; //doubleTapGesture.ShouldRecognizeSimultaneously += ShouldRecognizeSimultaneouslySingle; //doubleTapGesture.ShouldBeRequiredToFailBy += ShouldRecognizeSimultaneouslyDouble; singleTapGesture.RequireGestureRecognizerToFail(doubleTapGesture); this.AddGestureRecognizer(singleTapGesture); this.AddGestureRecognizer(doubleTapGesture); } // set scalefactor. _scaleFactor = (float)this.ContentScaleFactor; // create the cache renderer. _cacheRenderer = new MapRenderer<CGContextWrapper>( new CGContextRenderer(_scaleFactor)); _backgroundColor = SimpleColor.FromKnownColor(KnownColor.White).Value; }
public void RotationGestureUpdated(UIRotationGestureRecognizer rotationGesture) { switch (rotationGesture.State) { case UIGestureRecognizerState.Ended: case UIGestureRecognizerState.Cancelled: case UIGestureRecognizerState.Failed: { // TODO: WTF is this? //[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(transformingGestureDidFinish) object:nil]; PerformSelector(new Selector("transformingGestureDidFinish"),null,0.1); } break; case UIGestureRecognizerState.Began: { TransformingGestureDidBeginWithGesture(rotationGesture); } break; case UIGestureRecognizerState.Changed: { float rotation = rotationGesture.Rotation - lastRotation; CGAffineTransform currentTransform = transformingItem.ContentView.Transform; currentTransform.Rotate(rotation); CGAffineTransform newTransform = currentTransform; transformingItem.ContentView.Transform = newTransform; lastRotation = rotationGesture.Rotation; } break; default: { } break; } }
void updateGestures(object sender, EventArgs e) { var enabledGestures = TouchPanel.EnabledGestures; if ((enabledGestures & GestureType.Hold) != 0) { if (recognizerLongPress == null) { recognizerLongPress = new UILongPressGestureRecognizer(this, new Selector("LongPressGestureRecognizer")); recognizerLongPress.MinimumPressDuration = 1.0; AddGestureRecognizer(recognizerLongPress); } } else if (recognizerLongPress != null) { RemoveGestureRecognizer(recognizerLongPress); recognizerLongPress = null; } if ((enabledGestures & GestureType.Tap) != 0) { if (recognizerTap == null) { recognizerTap = new UITapGestureRecognizer(this, new Selector("TapGestureRecognizer")); recognizerTap.NumberOfTapsRequired = 1; AddGestureRecognizer(recognizerTap); } } else if (recognizerTap != null) { RemoveGestureRecognizer(recognizerTap); recognizerTap = null; } if ((enabledGestures & GestureType.DoubleTap) != 0) { if (recognizerDoubleTap == null) { recognizerDoubleTap = new UITapGestureRecognizer(this, new Selector("TapGestureRecognizer")); recognizerDoubleTap.NumberOfTapsRequired = 2; AddGestureRecognizer(recognizerDoubleTap); } } else if (recognizerDoubleTap != null) { RemoveGestureRecognizer(recognizerDoubleTap); recognizerDoubleTap = null; } if ((enabledGestures & GestureType.FreeDrag) != 0) { if (recognizerPan == null) { recognizerPan = new UIPanGestureRecognizer(this, new Selector("PanGestureRecognizer")); recognizerPan.CancelsTouchesInView = false; AddGestureRecognizer(recognizerPan); } } else if (recognizerPan != null) { RemoveGestureRecognizer(recognizerPan); recognizerPan = null; } if ((enabledGestures & GestureType.Flick) != 0) { if (recognizerLeftRightSwipe == null) { recognizerLeftRightSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer")); recognizerLeftRightSwipe.Direction = UISwipeGestureRecognizerDirection.Down | UISwipeGestureRecognizerDirection.Up | UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right; AddGestureRecognizer(recognizerLeftRightSwipe); } if (recognizerUpDownSwipe == null) { recognizerUpDownSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer")); recognizerUpDownSwipe.Direction = UISwipeGestureRecognizerDirection.Left | UISwipeGestureRecognizerDirection.Right; AddGestureRecognizer(recognizerUpDownSwipe); } } else if (recognizerLeftRightSwipe != null) { RemoveGestureRecognizer(recognizerLeftRightSwipe); recognizerLeftRightSwipe = null; } if ((enabledGestures & GestureType.Flick) != 0) { if (recognizerUpDownSwipe == null) { recognizerUpDownSwipe = new UISwipeGestureRecognizer(this, new Selector("SwipeGestureRecognizer")); recognizerUpDownSwipe.Direction = UISwipeGestureRecognizerDirection.Up | UISwipeGestureRecognizerDirection.Down; AddGestureRecognizer(recognizerUpDownSwipe); } } else if (recognizerUpDownSwipe != null) { RemoveGestureRecognizer(recognizerUpDownSwipe); recognizerUpDownSwipe = null; } if ((enabledGestures & GestureType.Pinch) != 0) { if (recognizerPinch == null) { recognizerPinch = new UIPinchGestureRecognizer(this, new Selector("PinchGestureRecognizer")); AddGestureRecognizer(recognizerPinch); } } else if (recognizerPinch != null) { RemoveGestureRecognizer(recognizerPinch); recognizerPinch = null; } if ((enabledGestures & GestureType.Rotation) != 0) { if (recognizerRotation == null) { recognizerRotation = new UIRotationGestureRecognizer(this, new Selector("RotationGestureRecognizer")); AddGestureRecognizer(recognizerRotation); } } else if (recognizerRotation != null) { RemoveGestureRecognizer(recognizerRotation); recognizerRotation = null; } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); var enabledGestures = TouchPanel.EnabledGestures; if ( enabledGestures != GestureType.None ) { if ((enabledGestures & GestureType.Hold) != 0) { recognizerLongPress = new UILongPressGestureRecognizer(this, new Selector ("LongPressGestureRecognizer")); recognizerLongPress.MinimumPressDuration = 1.0; AddGestureRecognizer(recognizerLongPress); } if ((enabledGestures & GestureType.Tap) != 0) { recognizerTap = new UITapGestureRecognizer(this, new Selector ("TapGestureRecognizer")); recognizerTap.NumberOfTapsRequired = 1; AddGestureRecognizer(recognizerTap); } if ((enabledGestures & GestureType.DoubleTap) != 0) { recognizerDoubleTap = new UITapGestureRecognizer(this, new Selector ("TapGestureRecognizer")); recognizerDoubleTap.NumberOfTapsRequired = 2; AddGestureRecognizer(recognizerDoubleTap); } if ((enabledGestures & GestureType.FreeDrag) != 0) { recognizerPan = new UIPanGestureRecognizer(this, new Selector ("PanGestureRecognizer")); AddGestureRecognizer(recognizerPan); } if ((enabledGestures & GestureType.Flick) != 0) { recognizerSwipe = new UISwipeGestureRecognizer(this, new Selector ("SwipeGestureRecognizer")); AddGestureRecognizer(recognizerSwipe); } if ((enabledGestures & GestureType.Pinch) != 0) { recognizerPinch = new UIPinchGestureRecognizer(this, new Selector ("PinchGestureRecognizer")); AddGestureRecognizer(recognizerPinch); } if ((enabledGestures & GestureType.Rotation) != 0) { recognizerRotation = new UIRotationGestureRecognizer(this, new Selector ("RotationGestureRecognizer")); AddGestureRecognizer(recognizerRotation); } } }
void Rotate(UIRotationGestureRecognizer gesture) { if (CurrentMonkey == null) return; if (gesture.State == UIGestureRecognizerState.Ended) { lastRotation = 0; CurrentMonkey.UpdateMonkey(0,this.Bounds); Parent.UpdateMonkey(CurrentMonkey.Monkey); return; } var rotation = 0 - (lastRotation - gesture.Rotation); var transform = CurrentMonkey.Transform; transform.Rotate (rotation); CurrentMonkey.Transform = transform; lastRotation = gesture.Rotation; }
private void CommonInit() { recog = new GridGestureRecognizer(this); tapGesture = new UITapGestureRecognizer(this,new Selector("tapGestureUpdated:")); tapGesture.Delegate = recog; tapGesture.NumberOfTapsRequired = 1; tapGesture.NumberOfTouchesRequired = 1; tapGesture.CancelsTouchesInView = false; AddGestureRecognizer(tapGesture); ///////////////////////////// // Transformation gestures : pinchGesture = new UIPinchGestureRecognizer(this,new Selector("pinchGestureUpdated:")); pinchGesture.Delegate = recog; AddGestureRecognizer(pinchGesture); rotationGesture = new UIRotationGestureRecognizer(this,new Selector("rotationGestureUpdated:")); rotationGesture.Delegate = recog; AddGestureRecognizer(rotationGesture); panGesture = new UIPanGestureRecognizer(this,new Selector("panGestureUpdated:")); panGesture.Delegate = recog; panGesture.MaximumNumberOfTouches=2; panGesture.MinimumNumberOfTouches=2; AddGestureRecognizer(panGesture); ////////////////////// // Sorting gestures : sortingPanGesture = new UIPanGestureRecognizer(this,new Selector("sortingPanGestureUpdated:")); sortingPanGesture.Delegate = recog; AddGestureRecognizer(sortingPanGesture); longPressGesture = new UILongPressGestureRecognizer(this,new Selector("longPressGestureUpdated:")); longPressGesture.NumberOfTouchesRequired = 1; longPressGesture.Delegate = recog; longPressGesture.CancelsTouchesInView = false; longPressGesture.DelaysTouchesBegan = true; longPressGesture.DelaysTouchesEnded = true; AddGestureRecognizer(longPressGesture); //////////////////////// // Gesture dependencies UIPanGestureRecognizer panGestureRecognizer = null; if (this.RespondsToSelector(new Selector("panGestureRecognizer")))// iOS5 only { panGestureRecognizer = this.PanGestureRecognizer; } else { foreach (UIGestureRecognizer gestureRecognizer in GestureRecognizers) { //if ([gestureRecognizer isKindOfClass:NSClassFromString(@"UIScrollViewPanGestureRecognizer")]) if (gestureRecognizer.ClassHandle.ToString().Equals("UIScrollViewPanGestureRecognizer")) // TODO: Test this! { panGestureRecognizer = (UIPanGestureRecognizer) gestureRecognizer; } } } panGestureRecognizer.MaximumNumberOfTouches = 1; panGestureRecognizer.RequireGestureRecognizerToFail(sortingPanGesture); //layoutStrategy = GMGridViewLayoutStrategyFactory.StrategyFromType(GMGridViewLayoutStrategyType.Vertical); SetLayoutStrategy(GridViewLayoutStrategyFactory.StrategyFromType(GridViewLayoutStrategyType.Vertical)); mainSuperView = this; editing = false; itemSpacing = 10; style = GridViewStyle.Swap; MinimumPressDuration = 0.2; showFullSizeViewWithAlphaWhenTransforming = true; minEdgeInsets = new UIEdgeInsets(5, 5, 5, 5); ClipsToBounds = false; sortFuturePosition = GMGV_INVALID_POSITION; itemSize = new SizeF(); centerGrid = true; lastScale = 1.0f; lastRotation = 0.0f; minPossibleContentOffset = new PointF(0,0); maxPossibleContentOffset = new PointF(0,0); //reusableCells = new HashSet<GMGridViewCell>(); reusableCells = new NSMutableSet(); NSNotificationCenter.DefaultCenter.AddObserver(this,new Selector("receivedMemoryWarningNotification:"),UIApplication.DidReceiveMemoryWarningNotification,null); NSNotificationCenter.DefaultCenter.AddObserver(this,new Selector("receivedWillRotateNotification:"),UIApplication.WillChangeStatusBarOrientationNotification,null); }