コード例 #1
0
        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.Frame> e)
        {
            base.OnElementChanged (e);

            if (e.NewElement != null) {
                _frame = e.NewElement as GesturedFrame;

                if (_frame.HasSwipeRightToLeft)
                    NativeView.AddGestureRecognizer (new UISwipeGestureRecognizer (g => _frame.DoSwipeRightToLeft ()) { Direction = UISwipeGestureRecognizerDirection.Left });

                if (_frame.HasSwipeLeftToRight)
                    NativeView.AddGestureRecognizer (new UISwipeGestureRecognizer (g => _frame.DoSwipeLeftToRight ()) { Direction = UISwipeGestureRecognizerDirection.Right });

                if (_frame.HasSwipeBottomToTop)
                    NativeView.AddGestureRecognizer (new UISwipeGestureRecognizer (g => _frame.DoSwipeBottomToTop ()) { Direction = UISwipeGestureRecognizerDirection.Up });

                if (_frame.HasSwipeTopToBottom)
                    NativeView.AddGestureRecognizer (new UISwipeGestureRecognizer (g => _frame.DoSwipeTopToBottom ()) { Direction = UISwipeGestureRecognizerDirection.Down });

                if (_frame.HasTap)
                    NativeView.AddGestureRecognizer (new UITapGestureRecognizer (g => _frame.DoTap ()) { NumberOfTapsRequired = 1 });

                if (_frame.HasLongTap)
                    NativeView.AddGestureRecognizer (new UILongPressGestureRecognizer (g => _frame.DoLongTap ()));
            }
        }
コード例 #2
0
        protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
        {
            base.OnElementChanged (e);

            _frame = e.NewElement as GesturedFrame;
            _gestureDetector = new GestureDetector (new InternalGestureCapture (_frame));

            this.ChildViewAdded += (object sender, ChildViewAddedEventArgs e2) => {
                e2.Child.Touch += (object sender2, TouchEventArgs e3) => _gestureDetector.OnTouchEvent (e3.Event);
            };
        }
コード例 #3
0
		public GestureFrameDemoPage ()
		{
			Title = "Coded Gesture Control";

			// Setup the Gesture Area
			GesturedFrame gestureArea = new GesturedFrame() { HeightRequest = 300 };

			var boxAnimLayout = new AbsoluteLayout () { BackgroundColor = Color.FromHex ("FCFCFC") };

			mainBox = new BoxView () { IsVisible = true, BackgroundColor = Color.Black };

			boxAnimLayout.Children.Add (mainBox, new Rectangle (currentLeft, currentTop, boxSize, boxSize));

			gestureArea.Content = boxAnimLayout;

			const int movementAmount = 75;

			gestureArea.OnSwipeLeftToRight += async (sender, args) => {
				log.Add("Swipe to Right");
				await MoveBox (movementAmount, 0);
			};
			gestureArea.OnSwipeRightToLeft += async (sender, args) => {
				log.Add("Swipe to Left");
				await MoveBox (-movementAmount, 0);
			};
			gestureArea.OnSwipeTopToBottom += async (sender, args) => {
				log.Add("Swipe to Bottom");
				await MoveBox (0, movementAmount);
			};
			gestureArea.OnSwipeBottomToTop += async (sender, args) => {
				log.Add("Swipe to Top");
				await MoveBox (0, -movementAmount);
			};
			gestureArea.OnTap += async (sender, args) => {
				log.Add("Tap");
				await ScaleBox (2);
			};
			gestureArea.OnLongTap += async (sender, args) => {
				log.Add("Long Press");
				await ScaleBox (1);
			};

			// Setup the Logger
	        var listView = new ListView
	        {
	            ItemsSource = log,
				ItemTemplate = new DataTemplate(typeof (TextCell))
	            {
	                Bindings =
	                {
	                    {TextCell.TextProperty, new Binding(".")},
	                }
	            }
			};

			RelativeLayout layout = new RelativeLayout ();
			layout.Children.Add (gestureArea, 
				Constraint.Constant (0),
				Constraint.Constant (0),
				Constraint.RelativeToParent (p => p.Width),
				Constraint.RelativeToParent (p => p.Height - 200));
			layout.Children.Add (listView, 
				Constraint.Constant (0),
				Constraint.RelativeToParent (p => p.Height - 200),
				Constraint.RelativeToParent (p => p.Width),
				Constraint.Constant(200));

			Content = layout;
		}