зеркало из https://github.com/xamarin/ios-samples.git
[Chat] update for iPhone X
This commit is contained in:
Родитель
e927cfcda6
Коммит
1b9192eb7d
|
@ -53,7 +53,7 @@ namespace Chat
|
|||
new Message { Type = MessageType.Incoming, Text = "And what do you think?" },
|
||||
new Message { Type = MessageType.Outgoing, Text = "I think it is the best way to develop mobile applications." },
|
||||
new Message { Type = MessageType.Incoming, Text = "Wow :-)" },
|
||||
new Message { Type = MessageType.Outgoing, Text = "Yep. Check it out\nhttp://Xamarin.com" },
|
||||
new Message { Type = MessageType.Outgoing, Text = "Yep. Check it out\nhttp://xamarin.com" },
|
||||
new Message { Type = MessageType.Incoming, Text = "Will do. Thanks" }
|
||||
};
|
||||
}
|
||||
|
@ -105,34 +105,57 @@ namespace Chat
|
|||
tableView.RegisterClassForCellReuse (typeof(OutgoingCell), OutgoingCell.CellId);
|
||||
View.AddSubview (tableView);
|
||||
|
||||
var pinLeft = NSLayoutConstraint.Create (tableView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1f, 0f);
|
||||
View.AddConstraint (pinLeft);
|
||||
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
|
||||
{ // iPhone X layout
|
||||
var safeGuide = View.SafeAreaLayoutGuide;
|
||||
tableView.TopAnchor.ConstraintEqualTo(safeGuide.TopAnchor).Active = true;
|
||||
tableView.LeadingAnchor.ConstraintEqualTo(safeGuide.LeadingAnchor).Active = true;
|
||||
tableView.TrailingAnchor.ConstraintEqualTo(safeGuide.TrailingAnchor).Active = true;
|
||||
tableView.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor, -44).Active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pinLeft = NSLayoutConstraint.Create(tableView, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1f, 0f);
|
||||
View.AddConstraint(pinLeft);
|
||||
|
||||
var pinRight = NSLayoutConstraint.Create (tableView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1f, 0f);
|
||||
View.AddConstraint (pinRight);
|
||||
var pinRight = NSLayoutConstraint.Create(tableView, NSLayoutAttribute.Trailing, NSLayoutRelation.Equal, View, NSLayoutAttribute.Trailing, 1f, 0f);
|
||||
View.AddConstraint(pinRight);
|
||||
|
||||
var pinTop = NSLayoutConstraint.Create (tableView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, 0f);
|
||||
View.AddConstraint (pinTop);
|
||||
|
||||
var pinBottom = NSLayoutConstraint.Create (tableView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1f, 0f);
|
||||
View.AddConstraint (pinBottom);
|
||||
var pinTop = NSLayoutConstraint.Create(tableView, NSLayoutAttribute.Top, NSLayoutRelation.Equal, TopLayoutGuide, NSLayoutAttribute.Bottom, 1f, 0f);
|
||||
View.AddConstraint(pinTop);
|
||||
|
||||
var pinBottom = NSLayoutConstraint.Create(tableView, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, View, NSLayoutAttribute.Bottom, 1f, 0f);
|
||||
View.AddConstraint(pinBottom);
|
||||
}
|
||||
chatSource = new ChatSource (messages);
|
||||
tableView.Source = chatSource;
|
||||
}
|
||||
|
||||
void SetUpToolbar ()
|
||||
void SetUpToolbar()
|
||||
{
|
||||
toolbar = new UIToolbar
|
||||
{
|
||||
toolbar = new UIToolbar {
|
||||
TranslatesAutoresizingMaskIntoConstraints = false
|
||||
};
|
||||
chatInputView = new ChatInputView {
|
||||
chatInputView = new ChatInputView
|
||||
{
|
||||
TranslatesAutoresizingMaskIntoConstraints = false
|
||||
};
|
||||
|
||||
toolbar.LayoutIfNeeded();
|
||||
View.AddSubview (toolbar);
|
||||
View.AddSubview(toolbar);
|
||||
|
||||
|
||||
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
|
||||
{ // iPhone X layout
|
||||
var safeGuide = View.SafeAreaLayoutGuide;
|
||||
toolbar.HeightAnchor.ConstraintEqualTo(44).Active = true;
|
||||
toolbar.LeadingAnchor.ConstraintEqualTo(safeGuide.LeadingAnchor).Active = true;
|
||||
toolbar.TrailingAnchor.ConstraintEqualTo(safeGuide.TrailingAnchor).Active = true;
|
||||
toolbar.BottomAnchor.ConstraintEqualTo(safeGuide.BottomAnchor).Active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
var pinLeft = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Leading, NSLayoutRelation.Equal, View, NSLayoutAttribute.Leading, 1f, 0f);
|
||||
View.AddConstraint (pinLeft);
|
||||
|
||||
|
@ -144,6 +167,7 @@ namespace Chat
|
|||
|
||||
toolbarHeightConstraint = NSLayoutConstraint.Create (toolbar, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 0f, 44f);
|
||||
View.AddConstraint (toolbarHeightConstraint);
|
||||
}
|
||||
|
||||
toolbar.AddSubview (chatInputView);
|
||||
|
||||
|
@ -223,12 +247,25 @@ namespace Chat
|
|||
void UpdateButtomLayoutConstraint (UIKeyboardEventArgs e)
|
||||
{
|
||||
UIViewAnimationCurve curve = e.AnimationCurve;
|
||||
UIView.Animate (e.AnimationDuration, 0, ConvertToAnimationOptions (e.AnimationCurve), () => {
|
||||
nfloat offsetFromBottom = tableView.Frame.GetMaxY () - e.FrameEnd.GetMinY ();
|
||||
offsetFromBottom = NMath.Max (0, offsetFromBottom);
|
||||
SetToolbarContstraint (offsetFromBottom);
|
||||
if (UIDevice.CurrentDevice.CheckSystemVersion(11, 0))
|
||||
{
|
||||
UIView.Animate(e.AnimationDuration, 0, ConvertToAnimationOptions(e.AnimationCurve), () =>
|
||||
{
|
||||
nfloat offsetFromBottom = tableView.Frame.GetMaxY() - e.FrameEnd.GetMinY();
|
||||
offsetFromBottom = NMath.Max(0, offsetFromBottom);
|
||||
|
||||
}, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
UIView.Animate(e.AnimationDuration, 0, ConvertToAnimationOptions(e.AnimationCurve), () =>
|
||||
{
|
||||
nfloat offsetFromBottom = tableView.Frame.GetMaxY() - e.FrameEnd.GetMinY();
|
||||
offsetFromBottom = NMath.Max(0, offsetFromBottom);
|
||||
SetToolbarContstraint(offsetFromBottom);
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
void SetToolbarContstraint (nfloat constant)
|
||||
{
|
||||
|
|
Двоичные данные
Chat/Screenshots/iPhone/iPhone.PNG
Двоичные данные
Chat/Screenshots/iPhone/iPhone.PNG
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 75 KiB После Ширина: | Высота: | Размер: 75 KiB |
Загрузка…
Ссылка в новой задаче