private void OnKeyboardNotification(NSNotification notification) { if (!IsViewLoaded) { return; } //Check if the keyboard is becoming visible var visible = notification.Name == UIKeyboard.WillShowNotification; //Start an animation, using values from the keyboard UIView.BeginAnimations("AnimateForKeyboard"); UIView.SetAnimationBeginsFromCurrentState(true); UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification)); UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification)); //Pass the notification, calculating keyboard height, etc. bool landscape = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight; var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification); OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height); //Commit the animation UIView.CommitAnimations(); }
private void TecladoArriba(NSNotification notif) { var r = UIKeyboard.FrameBeginFromNotification(notif); var keyboardHeight = r.Height; if (!blntecladoarriba) { CGRect newrect = new CGRect(View.Frame.X, View.Frame.Y - keyboardHeight, View.Frame.Width, View.Frame.Height); View.Frame = newrect; blntecladoarriba = true; } else { var rr = UIKeyboard.FrameEndFromNotification(notif); var hact = View.Frame.Y * -1; var hnew = rr.Height; var dif = hact - hnew; CGRect newrect = new CGRect(View.Frame.X, View.Frame.Y + dif, View.Frame.Width, View.Frame.Height); View.Frame = newrect; } }
private void OnKeyboardNotification(NSNotification notification) { //Check if the keyboard is becoming visible bool visible = notification.Name == UIKeyboard.WillShowNotification; //Start an animation, using values from the keyboard UIView.BeginAnimations("AnimateForKeyboard"); UIView.SetAnimationBeginsFromCurrentState(true); UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification)); UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification)); //Pass the notification, calculating keyboard height, etc. if (visible) { var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); OnKeyboardChanged(visible, keyboardFrame.Height); } else { var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification); OnKeyboardChanged(visible, keyboardFrame.Height); } //Commit the animation UIView.CommitAnimations(); }
/// <summary> /// Handleses the keyboard notifications. /// </summary> /// <param name="notification">Notification.</param> private void HandlesKeyboardNotifications(NSNotification notification) { // Check if the keyboard is becoming visible bool keyboardVisibile = notification.Name == UIKeyboard.WillShowNotification; // Start an animation, using values from the keyboard UIView.BeginAnimations("AnimateForKeyboard"); UIView.SetAnimationBeginsFromCurrentState(true); UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification) <= 0.0f ? 0.3f : UIKeyboard.AnimationDurationFromNotification(notification)); UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification)); // Pass the notification, calculating keyboard height, etc. bool landscape = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight; if (keyboardVisibile) { var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); _keyboardChanged.OnNext(new KeyboardData { IsVisible = keyboardVisibile, Height = landscape ? keyboardFrame.Width : keyboardFrame.Height }); } else { var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification); _keyboardChanged.OnNext(new KeyboardData { IsVisible = keyboardVisibile, Height = landscape ? keyboardFrame.Width : keyboardFrame.Height }); } // Commit the animation UIView.CommitAnimations(); }
private void TecladoArriba(NSNotification notif) { if (txtDescripcionobra.IsFirstResponder) { var r = UIKeyboard.FrameBeginFromNotification(notif); var keyboardHeight = r.Height; if (!blntecladoarriba) { var desface = (View.Frame.Y - keyboardHeight) + ajuste; CGRect newrect = new CGRect(View.Frame.X, desface, View.Frame.Width, View.Frame.Height); View.Frame = newrect; blntecladoarriba = true; } else { var rr = UIKeyboard.FrameEndFromNotification(notif); var hact = View.Frame.Y * -1; var hnew = rr.Height; var dif = hact - hnew; var desface = (View.Frame.Y + dif) + ajuste; CGRect newrect = new CGRect(View.Frame.X, desface, View.Frame.Width, View.Frame.Height); View.Frame = newrect; } } }
private void KeyBoardUpNotification(NSNotification notification) { // get the keyboard size var r = UIKeyboard.FrameBeginFromNotification(notification); // RectangleF r = UIKeyboard.BoundsFromNotification(notification); // Find what opened the keyboard //foreach (UIView view in this.View.Subviews) //{ // if (view.IsFirstResponder) // activeview = view; //} // Bottom of the controller = initial position + height + offset //bottom = (((float)((float)(this.View.Frame.Y) + this.View.Frame.Height))); bottom = ((float)(this.View.Frame.Height) + offset); // Calculate how far we need to scroll scroll_amount = ((float)(r.Height - (View.Frame.Size.Height - bottom))); // Perform the scrolling if (scroll_amount > 0) { moveViewUp = true; ScrollTheView(moveViewUp); } else { moveViewUp = false; } }
private void OnKeyboardNotification(NSNotification notification) { if (!IsViewLoaded) return; var visible = notification.Name == UIKeyboard.WillShowNotification; UIView.BeginAnimations("AnimateForKeyboard"); UIView.SetAnimationBeginsFromCurrentState(true); UIView.SetAnimationDuration(UIKeyboard.AnimationDurationFromNotification(notification)); UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification)); var landscape = InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight; if (visible) { var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification); OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height); } else { var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification); OnKeyboardChanged(visible, landscape ? keyboardFrame.Width : keyboardFrame.Height); } UIView.CommitAnimations(); }
protected virtual void KeyboardWillShowNotification(NSNotification notification) { UITextField activeView = (UITextField)this.tblView.FindFirstResponder(); if ((activeView == null)) { return; } var keyboardHeight = UIKeyboard.FrameBeginFromNotification(notification).Height + 30; //var keyboardHeight = 260; UIEdgeInsets contentInsets = new UIEdgeInsets(64.0f, 0.0f, keyboardHeight, 0.0f); tblView.ContentInset = contentInsets; tblView.ScrollIndicatorInsets = contentInsets; isKeyboardOpen = true; CGRect Frame = new CGRect(activeView.Frame.X, activeView.Frame.Y + 50, activeView.Frame.Size.Width, activeView.Frame.Size.Height); // Make sure the tapped location is visible. this.tblView.ScrollRectToVisible(Frame, true); }
private void KeyBoardUpNotification(NSNotification notification) { // get the keyboard size var r = (CGRect)UIKeyboard.FrameBeginFromNotification((NSNotification)notification); // Find what opened the keyboard foreach (UIView view in this.View.Subviews) { if (view.IsFirstResponder) { activeview = view; } } // Bottom of the controller = initial position + height + offset bottom = ((float)activeview.Frame.Y + (float)activeview.Frame.Height + Offset); // Calculate how far we need to scroll scrollamount = ((float)r.Height - ((float)View.Frame.Size.Height - bottom)); // Perform the scrolling if (scrollamount > 0) { moveViewUp = true; ScrollTheView(moveViewUp); } else { moveViewUp = false; } }
private void KeyboardOpened(NSNotification notification) { System.Console.WriteLine("Keyboard Opened"); UIView activeView = KeyboardGetActiveView(); if (activeView == null) { return; } var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification); var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardFrame.Height, 0.0f); newTimesheetScrollView.ContentInset = contentInsets; newTimesheetScrollView.ScrollIndicatorInsets = contentInsets; // Position of the active field relative inside the scroll view RectangleF relativeFrame = activeView.Superview.ConvertRectToView(activeView.Frame, newTimesheetScrollView); var spaceAboveKeyboard = newTimesheetScrollView.Frame.Height - keyboardFrame.Height; // Move the active field to the center of the available space var offset = relativeFrame.Y - (spaceAboveKeyboard - activeView.Frame.Height) / 2; newTimesheetScrollView.ContentOffset = new PointF(0, offset); }
public static nfloat ScrollOnHiddenUiElement(UIView view , float bottom , NSNotification notification , UIInterfaceOrientation interfaceOrientation) { var landscape = interfaceOrientation == UIInterfaceOrientation.LandscapeLeft || interfaceOrientation == UIInterfaceOrientation.LandscapeRight; var viewHeight = (landscape ? view.Frame.Width : view.Frame.Height); var spaceFromNavbarToTopKeyboard = viewHeight - UIKeyboard.FrameBeginFromNotification(notification).Height; return(spaceFromNavbarToTopKeyboard - bottom - 30); // 30 is extra offset }
private void OnKeyboardNotification(NSNotification notification) { var visible = notification.Name == UIKeyboard.WillShowNotification; var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification); if (KeyboardChanged != null) { KeyboardChanged(this, new KeyboardHelperEventArgs(visible, (float)keyboardFrame.Height)); } }
private void TecladoAbajo(NSNotification notif) { var r = UIKeyboard.FrameBeginFromNotification(notif); var keyboardHeight = r.Height; CGRect newrect = new CGRect(View.Frame.X, View.Frame.Y + keyboardHeight, View.Frame.Width, View.Frame.Height); View.Frame = newrect; blntecladoarriba = false; }
private void TecladoAbajo(NSNotification notif) { var r = UIKeyboard.FrameBeginFromNotification(notif); var keyboardHeight = r.Height; CGRect newrect = new CGRect(viewBarraChat.Frame.X, viewBarraChat.Frame.Y + keyboardHeight, viewBarraChat.Frame.Width, viewBarraChat.Frame.Height); viewBarraChat.Frame = newrect; blnTecladoArriba = false; heightact = 0; }
void OnKeyBoardEnabled(NSNotification notification) { if (!IsViewLoaded) { return; } var pageBounds = Element.Bounds; double yPosition = UIKeyboard.FrameBeginFromNotification(notification).Y - UIKeyboard.FrameEndFromNotification(notification).Y; var propertiesViewBounds = new Rectangle(Element.PropertiesView.X, Element.PropertiesView.Y - yPosition, Element.PropertiesView.Width, Element.PropertiesView.Height); Element.PropertiesView.Layout(propertiesViewBounds); }
private void OnKeyboardNotification(NSNotification notification) { NSNumber duration = (NSNumber)notification.UserInfo[UIKeyboard.AnimationDurationUserInfoKey]; int animationDuration = (int)(duration.FloatValue * 1000); var visible = notification.Name == UIKeyboard.WillShowNotification; var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification); KeyboardVisibilityChanged?.Invoke(this, new KeyboardVisibilityEventArgs(visible, (float)keyboardFrame.Height, animationDuration)); }
private void OnKeyboardHide(NSNotification notification) { if (!IsViewLoaded) { return; } var keyboardFrame = UIKeyboard.FrameBeginFromNotification(notification); if (_pageWasShiftedUp) { ShiftPageDown(keyboardFrame.Height, _activeViewBottom); } }
void OnKeyboardNotification(NSNotification notification) { if (!IsViewLoaded) { return; } var frameBegin = UIKeyboard.FrameBeginFromNotification(notification); var frameEnd = UIKeyboard.FrameEndFromNotification(notification); var bounds = Element.Bounds; var newBounds = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - frameBegin.Top + frameEnd.Top); Element.Layout(newBounds); }
void OnKeyboardNotification(NSNotification notification) { if (!IsViewLoaded) { return; } var frameBegin = UIKeyboard.FrameBeginFromNotification(notification); var frameEnd = UIKeyboard.FrameEndFromNotification(notification); var bounds = Element.Bounds; var newBounds = new Xamarin.Forms.Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - frameBegin.Top + frameEnd.Top); Element.Layout(newBounds); this.replaceKeyboardInputAccessoryView(); }
private void OnKeyboardNotification(NSNotification notification) { var visible = notification.Name == UIKeyboard.WillShowNotification; var keyboardFrame = visible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification); if (visible) { this.SetContentOffset(new CGPoint(this.Frame.Left, (this.Frame.Height - keyboardFrame.Height) / 2), false); } else { this.SetContentOffset(new CGPoint(this.Frame.Left, this.Frame.Top), false); } }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); _show = UIKeyboard.Notifications.ObserveWillShow((sender, e) => { var r = UIKeyboard.FrameBeginFromNotification(e.Notification); _scrollAmount = (float)r.Height; Scroll(sender, e, true); }); _hide = UIKeyboard.Notifications.ObserveWillHide((sender, e) => { Scroll(sender, e, false); _scrollAmount = 0; }); View.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth; }
void OnHideNotification(NSNotification notification) { if (!IsViewLoaded) { return; } MainTabbedPage.theModelEntryPage.KeyboardIsDown(); var frameBegin = UIKeyboard.FrameBeginFromNotification(notification); var frameEnd = UIKeyboard.FrameEndFromNotification(notification); var bounds = Element.Bounds; // var cover = 2 * MainTabbedPage.buttonHeightRequest + 20; // Height of the two bottom bars plus some random spacing var newBounds = new Rectangle(bounds.Left, bounds.Top, bounds.Width, bounds.Height - frameBegin.Top + frameEnd.Top // - cover // This causes random loss of the bottom toolbar ); Element.Layout(newBounds); }
void keyWillChange(NSNotification notification) { if (notification.Name == UIKeyboard.WillShowNotification) { var keyboard = UIKeyboard.FrameBeginFromNotification(notification); CGRect frame = View.Frame; frame.Y = -keyboard.Height; View.Frame = frame; } if (notification.Name == UIKeyboard.WillHideNotification) { CGRect frame = View.Frame; frame.Y = 0; View.Frame = frame; } }
void OnKeyboardNotification(NSNotification notification) { if (!IsViewLoaded) { return; } var frameBegin = UIKeyboard.FrameBeginFromNotification(notification); var frameEnd = UIKeyboard.FrameEndFromNotification(notification); var page = Element as ContentPage; if (page != null && !(page.Content is ScrollView)) { var padding = page.Padding; page.Padding = new Thickness(padding.Left, padding.Top, padding.Right, padding.Bottom + frameBegin.Top - frameEnd.Top); } }
private void Keyboard_DidShow(NSNotification notification) { var keyboardSize = UIKeyboard.FrameBeginFromNotification(notification).Size; if (InterfaceOrientation == UIInterfaceOrientation.LandscapeLeft || InterfaceOrientation == UIInterfaceOrientation.LandscapeRight) { keyboardSize.Width = Math.Max(keyboardSize.Height, keyboardSize.Width); keyboardSize.Height = Math.Min(keyboardSize.Height, keyboardSize.Width); } var view = (KeyboardInputView)View; var contentInsets = new UIEdgeInsets(0f, 0f, keyboardSize.Height, 0f); view.ContentInset = contentInsets; view.ScrollIndicatorInsets = contentInsets; view.ScrollActiveFieldToVisible(); }
public override void ViewDidLoad() { base.ViewDidLoad(); // style the text view to look like a text field - why the hell are they different? TextView.Layer.BorderColor = UIColor.Gray.ColorWithAlpha(0.5f).CGColor; TextView.Layer.BorderWidth = 2; TextView.Layer.CornerRadius = 5; TextView.ClipsToBounds = true; TaskDescriptionLabel.Text = thisTask.Description; _notification = UIKeyboard.Notifications.ObserveWillShow((s, e) => { _animationDuration = e.AnimationDuration; _animationCurve = e.AnimationCurve; CGRect r = UIKeyboard.FrameBeginFromNotification(e.Notification); _scrollAmount = r.Height; ScrollTheView(true); }); if (!string.IsNullOrWhiteSpace(thisTask.CompletionData?.JsonData)) { TextView.Text = thisTask.CompletionData.JsonData; } else { // Bootstrap for placeholder text. FML TextView.Delegate = new TextViewPlaceholderDelegate(TextView, placeholderText); } UIBarButtonItem customButton = new UIBarButtonItem( UIImage.FromBundle("TickIcon"), UIBarButtonItemStyle.Plain, (s, e) => { ReturnText(); } ); NavigationItem.RightBarButtonItem = customButton; }
private void KeyBoardUpNotification(NSNotification notification) { var r = UIKeyboard.FrameBeginFromNotification(notification); bottom = ((float)(this.View.Frame.Height) + offset); // Calculate how far we need to scroll scroll_amount = ((float)(r.Height - (View.Frame.Size.Height - bottom))); // Perform the scrolling if (scroll_amount > 0) { moveViewUp = true; ScrollTheView(moveViewUp); } else { moveViewUp = false; } }
private void TecladoArriba(NSNotification notif) { var r = UIKeyboard.FrameBeginFromNotification(notif); var keyboardHeight = r.Height; if (!blnTecladoArriba) { CGRect newrect = new CGRect(viewBarraChat.Frame.X, viewBarraChat.Frame.Y - keyboardHeight, viewBarraChat.Frame.Width, viewBarraChat.Frame.Height); viewBarraChat.Frame = newrect; blnTecladoArriba = true; heightact = keyboardHeight; } else { var rr = UIKeyboard.FrameEndFromNotification(notif); var hact = heightact; var hnew = rr.Height; var dif = hact - hnew; Console.WriteLine("hact " + hact.ToString()); Console.WriteLine("hnew " + hnew.ToString()); Console.WriteLine("dif " + dif.ToString()); CGRect newrect = new CGRect(viewBarraChat.Frame.X, viewBarraChat.Frame.Y + dif, viewBarraChat.Frame.Width, viewBarraChat.Frame.Height); viewBarraChat.Frame = newrect; heightact = hnew; } }
/// <summary> /// Called when the keyboard is raised. /// </summary> /// <param name="notification">Notification.</param> private void OnKeyboardUp(NSNotification notification) { var keyboardRect = UIKeyboard.FrameBeginFromNotification(notification); if (!FindActiveView(vc.View)) { Log.E(this, "Failed to find active view. Ignoring keyboard event"); return; } //var viewRect = FindBoundsInViewController(activeView, vc); //if((keyboardRect.Y - keyboardRect.Height) < (vc.View.Bounds.Bottom - keyboardRect.Height) ){ // return; //} //if (vc.View.Bounds.Bottom.Equals(keyboardRect.Y)) { // if (viewRect.Bottom < (keyboardRect.Y - keyboardRect.Height)) { // return; // } //} //else if (viewRect.Bottom < keyboardRect.Y) { // PerformScroll(-totalScrolled); // return; //} //var scrollAmount = viewRect.Bottom - keyboardRect.Height; //if((totalScrolled + scrollAmount) > keyboardRect.Height){ // scrollAmount = keyboardRect.Height - totalScrolled; //} //if (scrollAmount > 0) { // PerformScroll(scrollAmount); // scrolled = true; //} }
// Places the visible area of the scrollviewer at the top of the driver note. private void ObserveKeyboardShown(NSNotification notification) { var isKeyboardVisible = notification.Name == UIKeyboard.WillShowNotification; var keyboardFrame = isKeyboardVisible ? UIKeyboard.FrameEndFromNotification(notification) : UIKeyboard.FrameBeginFromNotification(notification); var duration = UIKeyboard.AnimationDurationFromNotification(notification); UIView.SetAnimationCurve((UIViewAnimationCurve)UIKeyboard.AnimationCurveFromNotification(notification)); AnimateAsync(duration, async() => { // We need to wait until the default animation from iOS stops before ajusting the scrollviewer to the correct location. await Task.Delay(1000); var activeView = KeyboardGetActiveView(); if (activeView == null) { return; } var scrollView = activeView.FindSuperviewOfType(this, typeof(UIScrollView)) as UIScrollView; if (scrollView == null) { return; } var contentInsets = new UIEdgeInsets(0.0f, 0.0f, keyboardFrame.Height, 0.0f); scrollView.ContentInset = contentInsets; scrollView.ScrollIndicatorInsets = contentInsets; // Move the active field to the top of the active view area. var offset = activeView.Frame.Y - ScrollingOffset; scrollView.ContentOffset = new CoreGraphics.CGPoint(0, offset); }); }