locked
Can I activate the camera using a GestureRecognizer? RRS feed

  • Question

  • User378106 posted

    I would like to activate the camera using a tap or gesturerecognizer in an specific area of the screen. e.g if I draw a circle of a square on the top corner of the screen, tha camera has to activate.

    Is it possible to achive?

    Wednesday, April 17, 2019 11:48 AM

Answers

  • User371688 posted

    You can try to listen in on this event, when you listen for an event, you can call the system camera. For example, when you touch a Frame two times, it will activate the camera, it will like this:

    public class TapInsideFrame : ContentPage
    {
        int tapCount;
    
        public TapInsideFrame()
        {
            var frame = new Frame
            {
                OutlineColor = Color.Accent,
                BackgroundColor = Color.Transparent,
                Padding = new Thickness(20, 100),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Content = new Label
                {
                    Text = "Tap Inside Frame",
                    FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
                }
            };
    
    
            var tapGestureRecognizer = 
                new TapGestureRecognizer();
            //tapGestureRecognizer.NumberOfTapsRequired = 2; // double-tap
            tapGestureRecognizer.Tapped += OnTapGestureRecognizerTapped;
            frame.GestureRecognizers.Add(tapGestureRecognizer);
    
    
            Content = new StackLayout
            {
                Children =
                {
                    frame,
                }
            };
        }
    
        void OnTapGestureRecognizerTapped(object sender, EventArgs args)
        {
            tapCount++;
            if (tapCount==2) {
                System.Diagnostics.Debug.WriteLine("open camera......"); // here open camera.....
            }
        }
    }
    

    Note: you can listen for the event you want in the frame.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, April 18, 2019 2:49 AM

All replies

  • User371688 posted

    You can try to listen in on this event, when you listen for an event, you can call the system camera. For example, when you touch a Frame two times, it will activate the camera, it will like this:

    public class TapInsideFrame : ContentPage
    {
        int tapCount;
    
        public TapInsideFrame()
        {
            var frame = new Frame
            {
                OutlineColor = Color.Accent,
                BackgroundColor = Color.Transparent,
                Padding = new Thickness(20, 100),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand,
                Content = new Label
                {
                    Text = "Tap Inside Frame",
                    FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label))
                }
            };
    
    
            var tapGestureRecognizer = 
                new TapGestureRecognizer();
            //tapGestureRecognizer.NumberOfTapsRequired = 2; // double-tap
            tapGestureRecognizer.Tapped += OnTapGestureRecognizerTapped;
            frame.GestureRecognizers.Add(tapGestureRecognizer);
    
    
            Content = new StackLayout
            {
                Children =
                {
                    frame,
                }
            };
        }
    
        void OnTapGestureRecognizerTapped(object sender, EventArgs args)
        {
            tapCount++;
            if (tapCount==2) {
                System.Diagnostics.Debug.WriteLine("open camera......"); // here open camera.....
            }
        }
    }
    

    Note: you can listen for the event you want in the frame.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, April 18, 2019 2:49 AM
  • User378106 posted

    @jezh Hello there, I will try it and I will let u know if it works. thanks :smile:

    Thursday, April 18, 2019 8:23 AM
  • User378106 posted

    @jezh thanks it worked!! :smiley:

    Monday, April 29, 2019 7:42 AM
  • User371688 posted

    Congrats, and I am glad I could help you.

    Monday, April 29, 2019 7:52 AM