【发布时间】:2022-01-22 12:34:08
【问题描述】:
我在框架上有一个 TapGestureRecognizer,它在 Android 上运行良好,但在 iOS 上只能在框架的边框上工作。
我不知道为什么会这样,我试图将它更改为 Frame 内 Grid 的 Grid GR 但这并没有改变任何东西,Frame 仍然只会在边框上被点击。
不知道是不是因为和安卓的布局不一样。
这是我的代码
XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="45"/>
<RowDefinition x:Name="SecondRowDefinition"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ContentView Content="{Binding Map}"
Grid.RowSpan="3"
VerticalOptions="FillAndExpand" />
<Frame x:Name="SearchFrame"
BackgroundColor="#0c0c0c"
HasShadow="False">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Image Source="icon_search_red_24"
VerticalOptions="Center"
HeightRequest="20" />
<Label TextColor="White"
FontSize="Small"
Text="Search place by name"
HorizontalTextAlignment="Start"
Grid.Column="1" />
</Grid>
<Frame.GestureRecognizers>
<TapGestureRecognizer
NumberOfTapsRequired="1"
Command="{Binding Source={RelativeSource AncestorType={x:Type vm:MapViewModel}}, Path=SearchBarTapped}"
Tapped="Search_Tapped">
</TapGestureRecognizer>
</Frame.GestureRecognizers>
</Frame>
后面的代码
public partial class MapPage : ContentPage
{
private readonly MapViewModel _mapViewModel;
public MapPage()
{
InitializeComponent();
if (Device.RuntimePlatform == Device.iOS)
{
SecondRowDefinition.Height = 100;
SearchFrame.HorizontalOptions = LayoutOptions.Fill;
SearchFrame.Margin = new Thickness(15, 40, 15, -40);
SearchFrame.Padding = new Thickness(10, 15, 96, 10);
SearchFrame.CornerRadius = 25;
CategoriesList.Margin = new Thickness(15, 5, 0, -10);
}
else
{
SecondRowDefinition.Height = 40;
SearchFrame.HorizontalOptions = LayoutOptions.Start;
SearchFrame.Margin = new Thickness(15, 11, 65, -6);
SearchFrame.Padding = new Thickness(10, 10, 96, 10);
SearchFrame.CornerRadius = 20;
CategoriesList.Margin = new Thickness(15, 8, 0, 0);
}
BindingContext = _mapViewModel = new MapViewModel();
}
protected override void OnAppearing()
{
base.OnAppearing();
_mapViewModel.OnAppearing();
}
private void Search_Tapped(object sender, EventArgs e)
{
if (Device.RuntimePlatform == Device.Android)
{
Vibration.Vibrate(TimeSpan.FromMilliseconds(10));
}
}
}
【问题讨论】:
标签: c# ios xamarin.forms