简体   繁体   中英

Xamarin Forms Tap gesture recognizer Ios doesn't work

I have a problem about some Gesture Recognizer into my Xamarin Forms project. I was working to set three Image into a grid layer to see a viewfinder with Zxing Forms library to go into specific page and manage the flash camera device.

After I compiled and build my project, into Android device works perfectly, besided Ios that when I touch an image of them they didn't work not at all. I don't make any mistake to write the code.

Tap recognizer for example are wrote like these:

var settingsGestureRecognizer = new TapGestureRecognizer();
settingsGestureRecognizer.NumberOfTapsRequired = 1;
settingsGestureRecognizer.Tapped += async(s, e) =>
    {
        // handle the tap
        NavigationPage nav = new NavigationPage(new SettingsPage());
        await Navigation.PushModalAsync(nav);
    };

And also, I add it into a button of a StackLayout like these

settingsImage = new Image
    {
        Source = ImageSource.FromFile(ConstantStringCollector.iconSettings),
        Aspect = Aspect.AspectFit,
        WidthRequest = 45,
        HeightRequest = 45,
        MinimumHeightRequest = 45,
        MinimumWidthRequest = 45,
        IsEnabled = true
    };
settingsImage.GestureRecognizers.Add(settingsGestureRecognizer);

And then there is my personal layout

StackLayout stackLayoutBottom = new StackLayout
{
    IsEnabled = true,
    IsVisible = true,
    IsClippedToBounds = true,
    Padding = new Thickness(20, 20),
    BackgroundColor = Color.Black,
    Opacity = 0.8,
    VerticalOptions = LayoutOptions.FillAndExpand,
    Orientation = StackOrientation.Horizontal,
    Children = {
                infoImage,
                flashImage,
                settingsImage
                }

};

Someone could help me?

if what you're trying to tap is visible, then I'd look at whether it is getting input, one option is to turn on InputTransparent for all the items except for the image and see if that lets your image recieve you input.

see: InputTransparent

Can you Try this

NavigationPage nav = new NavigationPage(new SettingsPage());
var settingsGestureRecognizer = new TapGestureRecognizer();
settingsGestureRecognizer.NumberOfTapsRequired = 1;
settingsGestureRecognizer.Tapped += async(s, e) =>
    {
        await Navigation.PushModalAsync(nav);
    };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM