我有这个问题,我的iOS应用程序部署,但有像一个无形的墙,不让我点击任何东西(这是仅适用于iOS).在Android上一切运行完美,没有打破据我所见
这里是登录页面xaml:
<Grid Padding="0" VerticalOptions="Center" RowDefinitions="Auto,Auto">
<Image x:Name="ImageLogo" Source="rcm_white_red_transpar.png" VerticalOptions="Center" WidthRequest="350" HeightRequest="104"/>
<VerticalStackLayout VerticalOptions="Center" Grid.Row="1" Padding="10">
<Entry x:Name="PhoneNumber" Keyboard="Telephone" BackgroundColor="White" Placeholder="Phone Number XXX-XXX-XXXX" HorizontalTextAlignment="Center" HeightRequest="50" WidthRequest="320" TextColor="Black" PlaceholderColor="SlateGray"/>
<Entry x:Name="PinNumber" Keyboard="Numeric" BackgroundColor="White" Placeholder="PIN Number XXXXXX" HorizontalTextAlignment="Center" HeightRequest="50" WidthRequest="320" IsVisible="false" TextColor="Black" PlaceholderColor="SlateGray"/>
<Button x:Name="ButtonSignIn" HeightRequest="50" WidthRequest="320" HorizontalOptions="Center" VerticalOptions="Center" FontSize="Large" Text="Sign In" Clicked="ButtonSignIn_Clicked" IsVisible="false" />
<Button x:Name="ButtonSendCode" HeightRequest="50" WidthRequest="320" HorizontalOptions="Center" VerticalOptions="Center" FontSize="Large" Text="Send PIN" Clicked="ButtonSendCode_Clicked" IsVisible="true" Margin="0,10,0,0"/>
</VerticalStackLayout>
<ActivityIndicator Color="{StaticResource Primary}" x:Name="LoginActivityIndicator" IsRunning="False"/>
</Grid>
这里是登录页面xaml.cs:
string logout_message_ = null;
public string logout_message
{
set
{
logout_message_ = value;
}
}
public LoginPage()
{
InitializeComponent();
this.BindingContext = new LoginViewModel();
http_client_ = App.GetBackendClient();
// In the accept header value, we tell that JSON is an acceptable response type.
http_client_.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// load our last phone number used
var task = SecureStorage.GetAsync("last_phone_number");
task.Wait();
var token = task.Result;
if (token != null)
{
PhoneNumber.Text = token;
}
}
//Override the OnAppearing function to load our MSAL
protected override async void OnAppearing()
{
//Disable the Flyout so user's cant get in unwarranted
Shell.Current.FlyoutBehavior = FlyoutBehavior.Disabled;
//show activity
LoginActivityIndicator.IsRunning = true;
if (logout_message_ != null)
{
await DisplayAlert("Logged Out", logout_message_, "Dismiss");
}
//Authenticate
try
{
var oauthToken = await App.GetCachedLogin();
if (oauthToken != null)
{
await App.Login(oauthToken);
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
}
catch (Exception ex)
{
// Do nothing - the user isn't logged in
await DisplayAlert("Error", ex.Message, "Dismiss");
}
LoginActivityIndicator.IsRunning = false;
base.OnAppearing();
}
//Override the OnDisappearing function to enable the Flyout when leaving
protected override void OnDisappearing()
{
Shell.Current.FlyoutBehavior = FlyoutBehavior.Flyout;
LoginActivityIndicator.IsRunning = false;
base.OnDisappearing();
}
//Button Send Code Command in LoginPage.xaml
private async void ButtonSendCode_Clicked(object sender, EventArgs e)
{
string phone_number = RemoveNonNumeric(PhoneNumber.Text);
string requestUri = "api/Login/start/" + phone_number + "/" + Constants.LoginSecretKey;
try
{
//send api call to backend
//if successful then unhide other buttons
HttpResponseMessage response = await http_client_.GetAsync(requestUri);
if (response.IsSuccessStatusCode)
{
ButtonSignIn.IsVisible = true;
PinNumber.IsVisible = true;
ButtonSendCode.Text = "Resend PIN";
// We generate a request and read the content asynchronously
string content = await response.Content.ReadAsStringAsync();
}
else if (response.StatusCode == (System.Net.HttpStatusCode)429)
{
await DisplayAlert("Error", "Too many pin requests. Please wait before trying again.", "Dismiss");
}
else
{
await DisplayAlert("Error", (int)response.StatusCode + ": " + response.ReasonPhrase, "Dismiss");
}
}
catch (Exception ex)
{
await DisplayAlert("An error has occurred", ex.Message, "Dismiss");
}
}
private async void ButtonSignIn_Clicked(object sender, EventArgs e)
{
string phone_number = RemoveNonNumeric(PhoneNumber.Text);
string user_pin = PinNumber.Text;
string requestUri = "api/Login/finish/" + phone_number + "/" + user_pin;
try
{
// need to call the phone login finish API and if successful with a token returned the login
HttpResponseMessage response = await http_client_.GetAsync(requestUri);
if (response.IsSuccessStatusCode)
{
// We generate a request and read the content asynchronously
var token = await response.Content.ReadAsStringAsync();
await App.Login(System.Text.Json.JsonSerializer.Deserialize<string>(token));
// save the last valid phone login for use on future launches
await SecureStorage.SetAsync("last_phone_number", PhoneNumber.Text);
PinNumber.Text = "";// clear our pin
await Shell.Current.GoToAsync($"//{nameof(HomePage)}");
}
else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
{
await DisplayAlert("Error", "Incorrect pin or phone number.", "Dismiss");
}
else
{
await DisplayAlert("Error", (int)response.StatusCode + ": " + response.ReasonPhrase, "Dismiss");
}
}
catch (Exception ex)
{
//Debug.WriteLine(ex.Message);
await DisplayAlert("An error has occurred", ex.Message, "Dismiss");
}
}
public static string RemoveNonNumeric(string text)
{
string newText = "";
if (String.IsNullOrEmpty(text))
{
return newText;
}
newText = Regex.Replace(text, "[^0-9]", "");
return newText;
}
下面是应用程序 shell ,如果它有帮助:
<!--
The overall app visual hierarchy is defined here, along with navigation.
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/
-->
<Shell.Resources>
<ResourceDictionary>
<DataTemplate x:Key="MenuItemRobotModeOff">
<Label x:Name="LabelRobotMode"
Text="Robot Mode OFF"
IsVisible="false"
HeightRequest="40"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="Large"
BackgroundColor="{StaticResource Primary}"
TextColor="{StaticResource Secondary}"/>
</DataTemplate>
<DataTemplate x:Key="MenuItemRobotModeOn">
<Label Text="Robot Mode ON"
HeightRequest="40"
IsVisible="false"
HorizontalTextAlignment="Center"
VerticalTextAlignment="Center"
FontSize="Large"
BackgroundColor="{StaticResource Active}"
TextColor="{StaticResource Secondary}"/>
</DataTemplate>
<Style x:Key="BaseStyle" TargetType="Element">
<Setter Property="Shell.BackgroundColor" Value="{StaticResource Primary}"/>
<Setter Property="Shell.ForegroundColor" Value="{StaticResource Secondary}"/>
<Setter Property="Shell.TitleColor" Value="{StaticResource Secondary}"/>
<Setter Property="Shell.DisabledColor" Value="#B4FFFFFF"/>
<Setter Property="Shell.UnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarBackgroundColor" Value="{StaticResource Primary}"/>
<Setter Property="Shell.TabBarForegroundColor" Value="{StaticResource Secondary}"/>
<Setter Property="Shell.TabBarUnselectedColor" Value="#95FFFFFF"/>
<Setter Property="Shell.TabBarTitleColor" Value="{StaticResource Secondary}"/>
</Style>
<Style TargetType="TabBar" BasedOn="{StaticResource BaseStyle}"/>
<Style TargetType="FlyoutItem" BasedOn="{StaticResource BaseStyle}"/>
<!--
Default Styles for all Flyout Items
https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyoutitem-and-menuitem-style-classes
-->
<Style Class="FlyoutItemLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="{StaticResource Secondary}"></Setter>
<!-- Change font for FlyoutItem to Custom Font -->
<Setter Property="FontFamily" Value="DINOTMedium.otf#DINOTMedium.otf"></Setter>
<Setter Property="TextTransform" Value="Uppercase"/>
</Style>
<Style Class="FlyoutItemLayoutStyle" TargetType="Layout" ApplyToDerivedTypes="True">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{x:OnPlatform iOS={AppThemeBinding Dark={StaticResource Accent}, Light={StaticResource Secondary},Default={StaticResource Accent}}, Android={AppThemeBinding Dark={StaticResource Accent}, Light={StaticResource Secondary},Default={StaticResource Accent}}}"/>
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Selected">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="{StaticResource Primary}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<!--Custom Style you can apply to any Flyout Item-->
<Style Class="MenuItemLayoutStyle" TargetType="Layout" >
<!--ApplyToDerivedTypes="True"-->
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter TargetName="FlyoutItemLabel" Property="Label.TextColor" Value="{StaticResource Primary}"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
<!--Custom Style for Robot Mode menu item -->
<Style Class="MenuItemRobotModeOnStyle" TargetType="Layout" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{StaticResource Active}"/>
</Style>
<Style Class="MenuItemRobotModeOffStyle" TargetType="Layout" ApplyToDerivedTypes="True">
<Setter Property="BackgroundColor" Value="{StaticResource Primary}"/>
</Style>
</ResourceDictionary>
</Shell.Resources>
<!--Default login Page-->
<ShellItem Route="Login">
<ShellContent ContentTemplate="{DataTemplate local:LoginPage}"/>
</ShellItem>
<!--
When the Flyout is visible this defines the content to display in the flyout.
FlyoutDisplayOptions="AsMultipleItems" will create a separate flyout item for each child element
https://docs.microsoft.com/dotnet/api/xamarin.forms.shellgroupitem.flyoutdisplayoptions?view=xamarin-forms
-->
<FlyoutItem x:Name="HomePage" Title="Home" Icon="{AppThemeBinding Dark=home_white.png,Light=home.png}">
<Tab>
<ShellContent Route="HomePage" ContentTemplate="{DataTemplate local:HomePage}"/>
</Tab>
</FlyoutItem>
<FlyoutItem x:Name="MowersPage" Title="Machines" Icon="{AppThemeBinding Dark=machine_white.png,Light=machine.png}">
<ShellContent Route="MowersPage" ContentTemplate="{DataTemplate local:MowersPage}"/>
</FlyoutItem>
<FlyoutItem x:Name="PlanPage" Title="Plan" Icon="{AppThemeBinding Dark=plan_white.png,Light=plan.png}">
<ShellContent Route="PlanPage" ContentTemplate="{DataTemplate local:PlanPage}" />
</FlyoutItem>
<FlyoutItem x:Name="MonitorPage" Title="Monitor" Icon="{AppThemeBinding Dark=monitor_white.png,Light=monitor.png}">
<ShellContent Route="MonitorPage" ContentTemplate="{DataTemplate local:MonitorPage}" />
</FlyoutItem>
<FlyoutItem x:Name="MowPage" Title="Mow" Icon="{AppThemeBinding Dark=mow_white.png,Light=mow.png}">
<ShellContent Route="MowPage" ContentTemplate="{DataTemplate local:MowPage}"/>
</FlyoutItem>
<!-- When the Flyout is visible this will be a menu item you can tie a click behavior to -->
<MenuItem x:Name="LogoutMenuItem" Text="Logout" StyleClass="MenuItemLayoutStyle" Clicked="OnMenuItemLogout_Clicked" />
<!--
TabBar lets you define content that won't show up in a flyout menu. When this content is active
the flyout menu won't be available. This is useful for creating areas of the application where
you don't want users to be able to navigate away from. If you would like to navigate to this
content you can do so by calling
await Shell.Current.GoToAsync("//LoginPage");
-->
<TabBar>
<ShellContent Route="LoginPage" ContentTemplate="{DataTemplate local:LoginPage}" />
</TabBar>
<!-- Optional Templates
// These may be provided inline as below or as separate classes.
// This header appears at the top of the Flyout.
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#flyout-header
<Shell.FlyoutHeaderTemplate>
<DataTemplate>
<Grid>ContentHere</Grid>
</DataTemplate>
</Shell.FlyoutHeaderTemplate>
// ItemTemplate is for ShellItems as displayed in a Flyout
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-flyoutitem-appearance
<Shell.ItemTemplate>
<DataTemplate>
<ContentView>
Bindable Properties: Title, Icon
</ContentView>
</DataTemplate>
</Shell.ItemTemplate>
// MenuItemTemplate is for MenuItems as displayed in a Flyout
// https://docs.microsoft.com/xamarin/xamarin-forms/app-fundamentals/shell/flyout#define-menuitem-appearance
<Shell.MenuItemTemplate>
<DataTemplate>
<ContentView>
Bindable Properties: Text, Icon
</ContentView>
</DataTemplate>
</Shell.MenuItemTemplate>
-->
<Shell.FlyoutFooter>
<StackLayout>
<Image x:Name="CustomerSupportImage" Source="{AppThemeBinding Dark={OnPlatform iOS=rcm_badge_horiz_cust_supp_phone.png, Android=Images/rcm_badge_horiz_cust_supp_phone.png}, Light={OnPlatform iOS=rcm_badge_horiz_cust_supp_phone_invert.png, Android=Images/rcm_badge_horiz_cust_supp_phone_invert.png},Default={OnPlatform iOS=rcm_badge_horiz_cust_supp_phone.png, Android=Images/rcm_badge_horiz_cust_supp_phone.png}}" WidthRequest="250" />
<Image Source="{AppThemeBinding Dark={OnPlatform iOS=rcm_white_red_transpar.png, Android=Images/rcm_white_red_transpar.png}, Light={OnPlatform iOS=rcm_black_red_transpar.png, Android=Images/rcm_black_red_transpar.png},Default={OnPlatform iOS=rcm_white_red_transpar.png, Android=Images/rcm_white_red_transpar.png}}" WidthRequest="40" HeightRequest="40" Margin="20"/>
</StackLayout>
</Shell.FlyoutFooter>
我试着在我的Mac Book上下载VS,看看问题是不是出在模拟器上,运气不好。我甚至在我的iPhone上试过,看不见的墙仍然存在
1条答案
按热度按时间ibps3vxo1#
调试时可以设置一个背景,看ActivityIndicator是否覆盖了其他控件,如果是被覆盖的控件,点击它是不能访问的。
解决方法是设置IsVisible属性。当ActivityIndicator运行时,将IsVisible设置为True。当ActivityIndicator停止时,将IsVisible设置为False。
希望对你有用。