public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); ConfigureNavigationBar(); if (Comparable != null) { _unitPicker.SetSelectedUnit(Comparable.UnitId); } else { _unitPicker.SetSelectedUnit(Comparison.UnitId); } _keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.DidShowNotification, (notification) => { var keyboardBounds = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey); var keyboardSize = keyboardBounds.RectangleFValue; _keyboardVisible = true; if (_pickerVisible) { _tableView.ScrollToActiveRow(); return; } UIView.Animate(0.3, () => { _tableView.Frame = new RectangleF(0, 0, View.Frame.Width, View.Frame.Height - keyboardSize.Height); }, () => { _tableView.ScrollToActiveRow(); }); }); _keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, (notification) => { _keyboardVisible = false; if (_pickerVisible) { return; } _tableView.Frame = new RectangleF(0, _tableView.ContentOffset.Y, View.Frame.Width, View.Frame.Height); UIView.Animate(0.3, () => { _tableView.Frame = new RectangleF(0, 0, View.Frame.Width, _tableView.Frame.Height); }, null); }); }
private void Initialize(int comparisonId) { ComparisonId = comparisonId; Comparison = DataService.GetComparison(comparisonId); View.BackgroundColor = UIColor.White; // add tableview _tableView = new ComparableTableView(new RectangleF(0, 0, View.Frame.Width, View.Frame.Height), UITableViewStyle.Grouped, Comparable, this); _tableView.OnEditUnit += (sender, args) => { _pickerVisible = true; if (_keyboardVisible) { _unitPicker.Frame = new RectangleF(0, View.Frame.Height - _unitPicker.Frame.Height, View.Frame.Width, 216); _tableView.Frame = new RectangleF(0, 0, View.Frame.Width, View.Frame.Height - _unitPicker.Frame.Height); } else { UIView.Animate(0.3, () => { _unitPicker.Frame = new RectangleF(0, View.Frame.Height - _unitPicker.Frame.Height, View.Frame.Width, 216); _tableView.Frame = new RectangleF(0, 0, View.Frame.Width, View.Frame.Height - _unitPicker.Frame.Height); }, () => { _tableView.ScrollToActiveRow(); }); } }; _tableView.OnProductNameChanged += (sender, args) => { _navigationItem.Title = string.IsNullOrEmpty(_tableView.Product) ? "Product" : _tableView.Product; }; _tableView.OnKeyboardDone += (sender, args) => { if (_pickerVisible) { _pickerVisible = false; _unitPicker.Frame = new RectangleF(0, 460, 320, 216); } _tableView.ResignTextFieldAsFirstResponder(); }; View.AddSubview(_tableView); // add unit picker _unitPicker = new UnitPicker(Comparison.UnitTypeId, new RectangleF(0, 460, 320, 216)); _unitPicker.OnSelectionChanged += (sender, args) => { _tableView.SetUnitText(_unitPicker.SelectedUnit.FullName); }; View.AddSubview(_unitPicker); }