[iOS] Images inside StackLayout/AbsoluteLayout doesn't receives touch event

MaruMaru DEMember ✭✭

Hi everyone,

I have two images inside of a StackLayout. I add this to my root AbsoluteLayout. On Android the touch events of the images are fired correctly but on iOS no touch is received, not from the images neither from the StackLayout. When I hook my root layout to a touch event its working, but I need my images to respond to my touch events.
Does anyone know what the cause could be?

Best Answer

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Try using a custom renderer for the image view and set UserInteractionEnabled to true on the native control. On iOS this defaults to false for UIImageView.

    If that works I think you should file a bug report. That should be easy enough to fix.

  • MaruMaru DEMember ✭✭

    @adamkemp Thanks for the quick tip. Sadly that doesn't do the trick. :/

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Could you attach a project showing what you're trying to do?

  • MaruMaru DEMember ✭✭
    edited June 2015

    @adamkemp Ok I found out what the problem is:

    Inside of my AbsoluteLayout there is a control that covers the whole screen (0, 0, 1, 1) but most of the area is transparent. On Android these transparent areas apparently relay the touch to the view under them while on iOS thats not the case. Is this a bug on Android?

    I mean it looks like transparent parts on images in Android don't block touch events for underlying views compared to iOS.

  • AndrewMobileAndrewMobile USMember ✭✭✭✭

    I wonder if you put a ContentView on the back of the image which has BackgroundColor="Transparent" and have Xamarin Forms Image with InputTransparent="False"
    you could use the ContentView to get the touches

  • Martin_OpdeMartin_Opde BEMember

    @Maru said:
    @adamkemp Ok I found out what the problem is:

    Inside of my AbsoluteLayout there is a control that covers the whole screen (0, 0, 1, 1) but most of the area is transparent. On Android these transparent areas apparently relay the touch to the view under them while on iOS thats not the case. Is this a bug on Android?

    I mean it looks like transparent parts on images in Android don't block touch events for underlying views compared to iOS.

    Try to put your image (or any control where you need a tap gesture recognizer) as the last child of your AbsolutLayout, after your control that takes the whole screen (0,0,1,1)

    For exemple :

        <AbsoluteLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
    
    
               <StackLayout Margin="10,10,10,8" AbsoluteLayout.LayoutFlags="All"                    
                                                AbsoluteLayout.LayoutBounds="0,0,1,1">
    
                    ...
                    ...
                    ..
    
            </StackLayout>
    
                <StackLayout HorizontalOptions="EndAndExpand"
                       AbsoluteLayout.LayoutFlags="PositionProportional"                
                                       AbsoluteLayout.LayoutBounds="1,0,AutoSize,AutoSize">
                            <StackLayout.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding EditCommand}"/>
                            </StackLayout.GestureRecognizers>
                <Label Text="MyText"/>
                            <iconize:IconLabel Text="md-mode-edit" FontSize="30" />
                        </StackLayout>
    
          </AbsoluteLayout>
    
Sign In or Register to comment.