2016-12-13 2 views
2

Ich erstellte eine UIViewController und legte ein Label und UITextView auf UIViewController.Tastatur versteckt UITextView in UIViewController Xamarin IOS

Ich möchte einige UITextView s auf meinem UIViewController eins unter einem anderen setzen. Ich verwende den Landscape-Modus nur in meiner App. Ich verwende Xamarin IOS für die Erstellung dieser App.

Der untere Bildschirm zeigt, was passiert! Kann mir bitte jemand helfen!

Showing UITextView.

Keyboard is hiding my textview field.

Antwort

1

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/

+0

"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

+0

activeview ist Ihre Tracking-Ansicht für das sehe meine aktualisierte Antwort. – KKRocks

+0

versuchen Sie dies für die Vermeidung von Missbilligung: http://StackOverflow.com/a/7785126/3901620 – KKRocks

Verwandte Themen