この度、個人ブログを閉鎖することなり、一定のアクセスがあった記事を記録として遺すことにしました。
以下は、2018年7月15日に投稿した記事の写しです。この記事がこの世の誰かの助けとなることを願います。
iOSでTableViewとかListViewの様なスクロールできるViewの下にContentViewを設置するとHeigthRequestで指定した高さを確保できない場合があります。
例えば、TableViewの下に高さ50のContentVIewを設置する以下の様なXAMLを書いてみます。
<StackLayout Spacing="0">
<TableView Intent="Settings">
<TableSection Title="TableSection">
<TextCell BindingContext="{x:Reference bottom}" Text="HeightRequest" Detail="{Binding HeightRequest}"/>
<TextCell BindingContext="{x:Reference bottom}" Text="Height" Detail="{Binding Height}"/>
</TableSection>
</TableView>
<ContentView x:Name="bottom" HeightRequest="50" BackgroundColor="Lime" />
</StackLayout>
実行結果は以下の通りです。
出典元は忘れてしまったので、なぜこうすべきかなどの説明はできませんが
TableView要素にRowHeight="-1" HeightRequest="-2"を追記することで解決します。
<StackLayout Spacing="0">
<TableView Intent="Settings" RowHeight="-1" HeightRequest="-2">
<TableSection Title="TableSection">
<TextCell BindingContext="{x:Reference bottom}" Text="HeightRequest" Detail="{Binding HeightRequest}"/>
<TextCell BindingContext="{x:Reference bottom}" Text="Height" Detail="{Binding Height}"/>
</TableSection>
</TableView>
<ContentView x:Name="bottom" HeightRequest="50" BackgroundColor="Lime" />
</StackLayout>
正直、一見しても良くわからないくらいの差なのですが、画面下にAdmobのバナーを設置したい場合などは、広告のフォーマットが変わったりするので注意が必要かと思います。