Sie müssen Beobachter in Ihrem Viewcontroller hinzuzufügen, wo dieses Problem wie unten auftritt.
Tastaturbeobachter für ViewDidLoad()
.
// Keyboard popup
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.DidShowNotification,KeyBoardUpNotification);
// Keyboard Down
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.WillHideNotification,KeyBoardDownNotification);
// Keyboard popup
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.DidShowNotification,KeyBoardUpNotification);
// Keyboard Down
NSNotificationCenter.DefaultCenter.AddObserver
(UIKeyboard.WillHideNotification,KeyBoardDownNotification);
Zuerst ist die KeyboardUpNotification
Methode. Im Wesentlichen berechnen Sie, ob das Steuerelement von der Tastatur ausgeblendet wird. Wenn ja, berechnen Sie, um wie viel die Ansicht verschoben werden muss, um das Steuerelement anzuzeigen, und verschieben Sie es anschließend.
private void KeyBoardUpNotification(NSNotification notification)
{
// get the keyboard size
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 = (activeview.Frame.Y + activeview.Frame.Height + offset);
// Calculate how far we need to scroll
scroll_amount = (r.Height - (View.Frame.Size.Height - bottom)) ;
// Perform the scrolling
if (scroll_amount > 0) {
moveViewUp = true;
ScrollTheView (moveViewUp);
} else {
moveViewUp = false;
}
}
private void KeyBoardUpNotification(NSNotification notification)
{
// get the keyboard size
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 = (activeview.Frame.Y + activeview.Frame.Height + offset);
// Calculate how far we need to scroll
scroll_amount = (r.Height - (View.Frame.Size.Height - bottom)) ;
// Perform the scrolling
if (scroll_amount > 0) {
moveViewUp = true;
ScrollTheView (moveViewUp);
} else {
moveViewUp = false;
}
}
Aktives Feld wird verwendet, um das gerade gestartete Textfeld zu verfolgen.
public override void EditingStarted (UITextField textfield) {
activeview = textField ;
}
für mehr: http://www.gooorack.com/2013/08/28/xamarin-moving-the-view-on-keyboard-show/
"BoundsFromNotification" ist depricated. Es funktioniert nicht. Was ist "Activeview"? Ist das die ID der UIView, die mit meinem UIViewController geliefert wurde? Meine UIView-Felder Name und Klasse sind leer, ich habe dies auf der Eigenschaftenseite meiner UIView überprüft. Was als nächstes zu tun? Ich habe einige Informationen von unten Link: [link] (https://developer.xamarin.com/api/member/MonoTouch.UIKit.UIKeyboard+Notifications.ObserveWillShow/) – Khaksar
activeview ist Ihre Tracking-Ansicht für das sehe meine aktualisierte Antwort. – KKRocks
versuchen Sie dies für die Vermeidung von Missbilligung: http://StackOverflow.com/a/7785126/3901620 – KKRocks