private void TrackGestureChaged (UIPinchGestureRecognizer pinchGestureRecognizer)
		{
			// compute the current pinch fraction
			float fraction = (float)(1f - pinchGestureRecognizer.Scale / startScale);
			shouldCompleteTransition = (fraction > 0.5);
			UpdateInteractiveTransition (fraction);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            UIPinchGestureRecognizer pinch = new UIPinchGestureRecognizer (handlePinchGesture);
            this.CollectionView.AddGestureRecognizer (pinch);
        }
Exemple #3
0
		public void Initialize() 
		{
			Map = new Map();

			_renderer = new MapRenderer();
			BackgroundColor = UIColor.White;
		
			InitializeViewport();

			ClipsToBounds = true;

			var pinchGesture = new UIPinchGestureRecognizer(PinchGesture) { Enabled = true };
			AddGestureRecognizer(pinchGesture);

			UIDevice.Notifications.ObserveOrientationDidChange((n, a) => {
				if (this.Window != null) {

					// after rotation all textures show up as white. I don't know why. 
					// By deleting all textures they are rebound and they show up properly.
					_renderer.DeleteAllBoundTextures();	

					Frame = new CGRect (0, 0, Frame.Width, Frame.Height);
					Map.Viewport.Width = Frame.Width;
					Map.Viewport.Height = Frame.Height;
					Map.NavigateTo(Map.Viewport.Extent);
				}});
							
		}
		// This method is invoked when the application has loaded and is ready to run. In this 
		// method you should instantiate the window, load the UI into it and then make the window
		// visible.
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			window = new UIWindow (UIScreen.MainScreen.Bounds);

			// create and initialize a UICollectionViewFlowLayout
			flowLayout = new UICollectionViewFlowLayout (){
				SectionInset = new UIEdgeInsets (25,5,10,5),
				MinimumInteritemSpacing = 5,
				MinimumLineSpacing = 5,
				ItemSize = new CGSize (100, 100)
			};

			circleLayout = new CircleLayout (Monkeys.Instance.Count){
				ItemSize = new CGSize (100, 100)
			};
		
			imagesController = new ImagesCollectionViewController (flowLayout);

			nfloat sf = 0.4f;
			UICollectionViewTransitionLayout trLayout = null;
			UICollectionViewLayout nextLayout;

			pinch = new UIPinchGestureRecognizer (g => {

				var progress = Math.Abs(1.0f -  g.Scale)/sf;

				if(trLayout == null){
					if(imagesController.CollectionView.CollectionViewLayout is CircleLayout)
						nextLayout = flowLayout;
					else
						nextLayout = circleLayout;

					trLayout = imagesController.CollectionView.StartInteractiveTransition (nextLayout, (completed, finished) => {	
						Console.WriteLine ("transition completed");
						trLayout = null;
					});
				}

				trLayout.TransitionProgress = (nfloat)progress;

				imagesController.CollectionView.CollectionViewLayout.InvalidateLayout ();

				if(g.State == UIGestureRecognizerState.Ended){
					if (trLayout.TransitionProgress > 0.5f)
						imagesController.CollectionView.FinishInteractiveTransition ();
					else
						imagesController.CollectionView.CancelInteractiveTransition ();
				}

			});

			imagesController.CollectionView.AddGestureRecognizer (pinch);

			window.RootViewController = imagesController;
			window.MakeKeyAndVisible ();
			
			return true;
		}
		public override void ViewDidLoad ()
		{
			CollectionView.RegisterClassForCell (typeof (Cell), cellClass);

			var pinchRecognizer = new UIPinchGestureRecognizer (handlePinchGesture);
			handlePinchGesture (pinchRecognizer);

			CollectionView.AddGestureRecognizer (pinchRecognizer);
		}
		private void TrackGestureEnded (UIPinchGestureRecognizer pinchGestureRecognizer)
		{
			InteractionInProgress = false;
			if (!shouldCompleteTransition || pinchGestureRecognizer.State == UIGestureRecognizerState.Cancelled) {
				CancelInteractiveTransition ();
			} else {
				FinishInteractiveTransition ();
			}
		}
        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);
        }
        public void Initialize()
        {
            Map = new Map();
            BackgroundColor = UIColor.White;
            _renderer = new MapRenderer(this);

            InitializeViewport();

            ClipsToBounds = true;

            var pinchGesture = new UIPinchGestureRecognizer(PinchGesture) { Enabled = true };
            AddGestureRecognizer(pinchGesture);
        }
        public void handlePinchGesture(UIPinchGestureRecognizer gesture)
        {
            if (gesture.State == UIGestureRecognizerState.Began)
            {
                scaleStart = this.scale;
            }
            else if (gesture.State == UIGestureRecognizerState.Changed)
            {
                this.scale = scaleStart * gesture.Scale;

                this.CollectionView.CollectionViewLayout.InvalidateLayout ();
            }
        }
        private void CreatePinchGestureRecognizer()
        {
            pinchGesture = new UIPinchGestureRecognizer(() =>
            {

                if ((pinchGesture.State == UIGestureRecognizerState.Began ||
                     pinchGesture.State == UIGestureRecognizerState.Changed) && (pinchGesture.NumberOfTouches == 2))
                {
                    pinchGesture.View.Transform *= CGAffineTransform.MakeScale(pinchGesture.Scale, pinchGesture.Scale);
                    pinchGesture.Scale = 1;
                }
             });
        }
        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 FAViewController(UICollectionViewFlowLayout layout, FAViewSize size)
            : base(layout)
        {
            _fasize = size;

            _datasource = FA.Empty.Values();
            _searchresult = _datasource;
            _searchbar = new UISearchBar ();
            _searchbar.SearchBarStyle = UISearchBarStyle.Prominent;
            _pinchrecognizer = new UIPinchGestureRecognizer (PinchDetected);

            var searchdelegate = new UISearchFADelegate(this, _searchbar);
            _searchbar.Delegate = searchdelegate;
        }
		private void TrackGestureBegan (UIPinchGestureRecognizer pinchGestureRecognizer)
		{
			startScale = pinchGestureRecognizer.Scale;

			// start an interactive transition!
			InteractionInProgress = true;

			// perform the required operation
			if (operation == CEInteractionOperation.Pop) {
				viewController.NavigationController.PopViewController (true);
			} else {
				viewController.DismissViewController (true, null);
			}
		}
		public void HandlePinch (UIPinchGestureRecognizer pinchGestureRecognizer)
		{
			switch (gestureRecognizer.State) {
			case UIGestureRecognizerState.Began:
				TrackGestureBegan (pinchGestureRecognizer);
				break;
			case UIGestureRecognizerState.Changed:
				TrackGestureChaged (pinchGestureRecognizer);
				break;
			case UIGestureRecognizerState.Ended:
			case UIGestureRecognizerState.Cancelled:
				TrackGestureEnded (pinchGestureRecognizer);
				break;
			}
		}
		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;
			}
		}
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_swipeDown != null)
         {
             _swipeDown.Dispose();
             _swipeDown = null;
         }
         if (_swipeLeft != null)
         {
             _swipeLeft.Dispose();
             _swipeLeft = null;
         }
         if (_swipeRight != null)
         {
             _swipeRight.Dispose();
             _swipeRight = null;
         }
         if (_swipeUp != null)
         {
             _swipeUp.Dispose();
             _swipeUp = null;
         }
         if (_doubleTap != null)
         {
             _doubleTap.Dispose();
             _doubleTap = null;
         }
         if (_singleTap != null)
         {
             _singleTap.Dispose();
             _singleTap = null;
         }
         if (_pinch != null)
         {
             _pinch.Dispose();
             _pinch = null;
         }
     }
     // don't try and dispose the base - it will try and dispose of the native control that we didn't create
     //base.Dispose(disposing);
 }
		public void handlePinchGesture (UIPinchGestureRecognizer sender)
		{
			PinchLayout pinchLayout = (PinchLayout) CollectionView.CollectionViewLayout;

			switch (sender.State) {
			case UIGestureRecognizerState.Began:
				CGPoint initialPinchPoint = sender.LocationInView (CollectionView);
				pinchLayout.pinchedCellPath = CollectionView.IndexPathForItemAtPoint (initialPinchPoint);
				break;
			case UIGestureRecognizerState.Changed:
				pinchLayout.setPinchedCellScale ((float)sender.Scale);
				pinchLayout.setPinchedCellCenter (sender.LocationInView (CollectionView));
				break;
			default:
				CollectionView.PerformBatchUpdates (delegate {
					pinchLayout.pinchedCellPath = null;
					pinchLayout.setPinchedCellScale (1.0f);
				}, null);
				break;
			}
		}
		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);
			}
		}
		public iOS_PinchGestureEventArgs(PinchGestureRecognizer gestureRecognizer, UIPinchGestureRecognizer platformGestureRecognizer)
		{
			this.gestureRecognizer = gestureRecognizer;
			this.platformGestureRecognizer = platformGestureRecognizer;
		}
        private void Initialize()
        {
			BackgroundColor = GlobalTheme.BackgroundColor;
			UserInteractionEnabled = true;
			MultipleTouchEnabled = true;

			_doubleTapGesture = new UITapGestureRecognizer(HandleDoubleTapGestureRecognizer);
            _doubleTapGesture.DelaysTouchesBegan = true;
            _doubleTapGesture.NumberOfTapsRequired = 2;
			AddGestureRecognizer(_doubleTapGesture);
            
			_pinchGesture = new UIPinchGestureRecognizer(HandlePinchGestureRecognizer);
            AddGestureRecognizer(_pinchGesture);

			_panGesture = new UIPanGestureRecognizer(HandlePanGestureRecognizer);
			_panGesture.MinimumNumberOfTouches = 1;
			_panGesture.MaximumNumberOfTouches = 1;
			AddGestureRecognizer(_panGesture);

            WaveFormView = new SessionsWaveFormView(new RectangleF(0, _scaleHeight, Bounds.Width, Bounds.Height - _scaleHeight));
            AddSubview(WaveFormView);

            WaveFormScaleView = new SessionsWaveFormScaleView(new RectangleF(0, 0, Bounds.Width, _scaleHeight));
            AddSubview(WaveFormScaleView);

			WaveFormView.AddGestureRecognizer(_doubleTapGesture);

            _lblZoom = new UILabel(new RectangleF(0, 0, 60, 20));
            _lblZoom.BackgroundColor = GlobalTheme.BackgroundColor;
            _lblZoom.TextColor = UIColor.White;
			_lblZoom.Font = UIFont.FromName("HelveticaNeue", 11);
            _lblZoom.TextAlignment = UITextAlignment.Center;
            _lblZoom.Text = "100.0%";
            _lblZoom.Alpha = 0;
            AddSubview(_lblZoom);

            _viewCenterLine = new UIView(new RectangleF(Bounds.Width / 2, 0, 1, Bounds.Height));
            _viewCenterLine.BackgroundColor = GlobalTheme.LightColor;
            _viewCenterLine.Alpha = 0;
            AddSubview(_viewCenterLine);
        }
		private void HandlePinchGestureRecognizer(UIPinchGestureRecognizer sender)
		{
			if (sender.State == UIGestureRecognizerState.Began)
			{
				_initialZoom = Zoom;
				_initialContentOffset = WaveFormView.ContentOffset;
				UIView.Animate(0.2, () => _lblZoom.Alpha = 0.9f);
			}
			else if (sender.State == UIGestureRecognizerState.Ended)
			{
				UIView.Animate(0.2, 0.8, UIViewAnimationOptions.CurveEaseOut, () => _lblZoom.Alpha = 0, () => {});
			}

			var location = sender.LocationInView(this);
			float newZoom = _initialZoom * _pinchGesture.Scale;
			float deltaZoom = newZoom / Zoom;
			float originPointX = IsAutoScrollEnabled ? WaveFormView.ContentOffset.X + (Frame.Width / 2) : location.X + WaveFormView.ContentOffset.X;
			float distanceToOffsetX = originPointX - WaveFormView.ContentOffset.X;
			float contentOffsetX = (originPointX * deltaZoom) - distanceToOffsetX;
			Zoom = Math.Max(1, newZoom);
			SetContentOffsetX(contentOffsetX);
			_lblZoom.Text = (Zoom * 100).ToString("0") + "%";
			//Console.WriteLine("HandlePinchGestureRecognizer - initialZoom: {0} newZoom: {1}", _initialZoom, newZoom);
		}
Exemple #22
0
        /// <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;
        }
Exemple #23
0
        /// <summary>
        /// Pinch the specified pinch.
        /// </summary>
        /// <param name="pinch">Pinch.</param>
        private void Pinch(UIPinchGestureRecognizer pinch)
        {
            CGRect rect = this.Frame;
            if (this.MapAllowZoom &&
                rect.Width > 0)
            {
                this.StopCurrentAnimation();
                if (pinch.State == UIGestureRecognizerState.Ended)
                {
                    this.NotifyMovementByInvoke();

                    _mapZoomLevelBefore = null;

                    // raise map touched event.
                    this.RaiseMapTouched();
                    this.RaiseMapTouchedUp();
                }
                else if (pinch.State == UIGestureRecognizerState.Began)
                {
                    this.RaiseMapTouchedDown();
                    _mapZoomLevelBefore = MapZoom;
                }
                else
                {
                    MapZoom = _mapZoomLevelBefore.Value;

                    double zoomFactor = this.Map.Projection.ToZoomFactor(MapZoom);
                    zoomFactor = zoomFactor * pinch.Scale;
                    MapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor);

                    this.NotifyMovementByInvoke();

                    // raise map move event.
                    this.RaiseMapMove();
                }
            }
        }
        protected void PinchDetected(UIPinchGestureRecognizer pinch)
        {
            if (pinch.State != UIGestureRecognizerState.Ended) {
                return;
            }

            var location = pinch.LocationInView (CollectionView);
            var path = CollectionView.IndexPathForItemAtPoint (location);
            if (path == null) {
                var visiblecells = CollectionView.IndexPathsForVisibleItems;
                int center = visiblecells.Length / 2;
                path = visiblecells [center];
            }
            if (pinch.Scale > 1) {
                _fasize.Increment ();
            }

            if (pinch.Scale < 1) {
                _fasize.Decrement ();
            }

            Zoom (path);
        }
		// Scales the image by the current scale
		void ScaleImage (UIPinchGestureRecognizer gestureRecognizer)
		{
			AdjustAnchorPointForGestureRecognizer (gestureRecognizer);
			if (gestureRecognizer.State == UIGestureRecognizerState.Began || gestureRecognizer.State == UIGestureRecognizerState.Changed) {
				gestureRecognizer.View.Transform *= CGAffineTransform.MakeScale (gestureRecognizer.Scale, gestureRecognizer.Scale);
				// Reset the gesture recognizer's scale - the next callback will get a delta from the current scale.
				gestureRecognizer.Scale = 1;
			}
		}
Exemple #26
0
        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;
            }
        }
		private void PrepareGestureRecognizerInView (UIView view)
		{
			gestureRecognizer = new UIPinchGestureRecognizer (HandlePinch);
			view.AddGestureRecognizer (gestureRecognizer);
		}
Exemple #28
0
        /// <summary>
        /// Pinch the specified pinch.
        /// </summary>
        /// <param name="pinch">Pinch.</param>
        private void Pinch(UIPinchGestureRecognizer pinch)
        {
            //RectangleF2D rect = _rect;
            RectangleF rect = this.Frame;
            if (this.MapAllowZoom &&
                rect.Width > 0)
            {
                this.StopCurrentAnimation();
                if (pinch.State == UIGestureRecognizerState.Ended)
                {
            //					_mapZoom = _mapZoomLevelBefore.Value;
            //
            //					double zoomFactor = this.Map.Projection.ToZoomFactor (this.MapZoom);
            //					zoomFactor = zoomFactor * pinch.Scale;
            //					_mapZoom = (float)this.Map.Projection.ToZoomLevel (zoomFactor);
            //
            //					this.NormalizeZoom ();

                    this.Change(true); // notifies change.

                    _mapZoomLevelBefore = null;
                }
                else if (pinch.State == UIGestureRecognizerState.Began)
                {
                    _mapZoomLevelBefore = _mapZoom;
                }
                else
                {
                    _mapZoom = _mapZoomLevelBefore.Value;

                    double zoomFactor = this.Map.Projection.ToZoomFactor(_mapZoom);
                    zoomFactor = zoomFactor * pinch.Scale;
                    _mapZoom = (float)this.Map.Projection.ToZoomLevel(zoomFactor);

                    this.NormalizeZoom();

                    this.InvokeOnMainThread(InvalidateMap);
                }
            }
        }
Exemple #29
0
		UIPinchGestureRecognizer CreatePinchRecognizer(Action<UIPinchGestureRecognizer> action)
		{
			var result = new UIPinchGestureRecognizer(action);
			return result;
		}
		// 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);
		}