pokrowce na klawiaturę iPhone UITextField
Mam aplikację, w której w Interface Builder ustawiam UIView
, która ma pole tekstowe u dołu widoku. Kiedy uruchamiam aplikację i próbuję wprowadzić tekst do tego pola, klawiatura przesuwa się na wierzch pola, więc nie mogę zobaczyć, co piszę, dopóki nie ukryję klawiatury ponownie.
Czy ktoś jeszcze napotkał ten problem i znalazł dobry sposób na rozwiązanie go bez przewijania widoku nadrzędnego lub przesuwania pola tekstowego dalej w górę ekranu?
20 answers
Zwyczajowym rozwiązaniem jest przesunięcie pola (i wszystkiego nad nim) w górę za pomocą animacji, a następnie z powrotem w dół, gdy skończysz. Może być konieczne umieszczenie pola tekstowego i niektórych innych elementów w innym widoku i przesunięcie widoku jako jednostki. (Ja nazywam te rzeczy " płytami "jak w " płytami tektonicznymi" , ale to tylko ja). Ale oto ogólna idea, jeśli nie musisz się wymyślać.
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-10-10 01:53:21
To zdziałało cuda dla mnie sliding uitextfields
W szczególności ma on tę zaletę, że oblicza odległość animacji slajdów w zależności od położenia pola tekstowego.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-19 13:13:27
IQKeyboardManager zrób to za Ciebie z BEZ linii kodu , wystarczy przeciągnąć i upuścić powiązany plik źródłowy do projektu. IQKeyboardManager obsługuje również orientację urządzenia , Automatyczne zarządzanie UIToolbar, keyboardDistanceFromTextField i znacznie więcej niż myślisz.
Oto schemat sterowania:
Krok 1: - Dodano globalne powiadomienia o UITextField
, UITextView
, oraz UIKeyboard
w klasie singletonów. Nazwałem go IQKeyboardManager.
Krok 2: - jeśli znaleziono UIKeyboardWillShowNotification
, UITextFieldTextDidBeginEditingNotification
lub UITextViewTextDidBeginEditingNotification
powiadomień, a następnie spróbuj pobrać instancję topMostViewController
z hierarchii UIWindow.rootViewController
. Aby prawidłowo odkryć UITextField
/UITextView
na nim rama topMostViewController.view
musi zostać dostosowana.
Krok 3: - obliczono oczekiwaną odległość ruchu topMostViewController.view
w odniesieniu do pierwszej odpowiedzi UITextField
/UITextView
.
Krok 4: - przesunięty topMostViewController.view.frame
w górę/w dół zgodnie z oczekiwanym ruchem odległość.
Krok 5: - jeśli znaleziono UIKeyboardWillHideNotification
, UITextFieldTextDidEndEditingNotification
lub UITextViewTextDidEndEditingNotification
notification, następnie ponownie spróbuj pobrać instancję topMostViewController
z hierarchii UIWindow.rootViewController
.
Krok 6: - obliczenie dystansu topMostViewController.view
, który należy przywrócić do pierwotnej pozycji.
Krok 7: - przywrócony topMostViewController.view.frame
w dół zgodnie z zakłóconą odległością.
Krok 8: - instancja singleton iqkeyboardmanager instancja klasy przy ładowaniu aplikacji, więc każdy UITextField
/UITextView
w aplikacji dostosuje się automatycznie w zależności od oczekiwanej odległości ruchu.
To wszystko
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-12-18 16:25:18
Aby rozwinąć odpowiedź Amagrammer, oto przykładowa klasa:
LoginViewController.h
@interface LoginViewController : UIViewController <UITextFieldDelegate> {
}
@property (nonatomic, retain) IBOutlet UITextField *emailTextField;
@property (nonatomic, retain) IBOutlet UITextField *passwordTextField;
Uwaga wdrażamy "UITextFieldDelegate"
LoginViewController.m
@implementation LoginViewController
@synthesize emailTextField=_emailTextField;
@synthesize passwordTextField=_passwordTextField;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//Register to receive an update when the app goes into the backround
//It will call our "appEnteredBackground method
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appEnteredBackground)
name:UIApplicationDidEnterBackgroundNotification
object:nil];
}
return self;
}
- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self animateTextField: textField up: YES];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
[self animateTextField: textField up: NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
//This is called when the app goes into the background.
//We must reset the responder because animations will not be saved
- (void)appEnteredBackground{
[self.emailTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-02-18 14:59:27
Co powiesz na oficjalne rozwiązanie: przenoszenie zawartości znajdującej się pod klawiaturą
Dostosowanie treści zazwyczaj wiąże się z tymczasową zmianą rozmiaru lub więcej widoków i pozycjonowanie ich tak, aby obiekt tekstowy pozostał widoczne. Najprostszym sposobem zarządzania obiektami tekstowymi za pomocą klawiatury jest aby osadzić je wewnątrz obiektu UIScrollView (lub jednej z jego podklas jak UITableView). Gdy klawiatura jest wyświetlana, wszystko, co musisz zrobić resetuje obszar zawartości widoku przewijania i przewijania żądanego obiekt tekstowy na pozycji. Tak więc, w odpowiedzi na UIKeyboardDidShowNotification, twoja metoda obsługi zrobiłaby "po": {]}
- Pobierz rozmiar klawiatury.
- Dostosuj dolną zawartość widoku przewijania za pomocą klawiatury wzrost.
- Przewiń docelowe pole tekstowe do widoku.
// Call this method somewhere in your view controller setup code.
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillBeHidden:)
name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
NSDictionary* info = [aNotification userInfo];
CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your app might not need or want this behavior.
CGRect aRect = self.view.frame;
aRect.size.height -= kbSize.height;
if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
[self.scrollView scrollRectToVisible:activeField.frame animated:YES];
}
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrollView.contentInset = contentInsets;
scrollView.scrollIndicatorInsets = contentInsets;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-12 03:27:42
Mam ten sam problem w komórkach UITableView
textField. Rozwiązuję ten problem, wdrażając następującą metodę odsłuchiwania powiadomienia z klawiatury.
Obserwator dla powiadomień tutaj:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
Obsługa tych powiadomień za pomocą poniższej funkcji:
(void)keyboardWasShown:(NSNotification*)aNotification
(void)keyboardWillBeHidden:(NSNotification*)aNotification
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-30 13:50:22
Zobacz też Nie ma dla Ciebie kłopotów.
To rozwiązanie jest bardzo schludne. Wszystko, co musisz zrobić, to dodać swoje pola tekstowe w UIScrollView
I zmienić jego klasę na TPKeyboardAvoidingScollView
, Jeśli używasz storyboardów. Widok przewijania jest rozszerzony w taki sposób, że wykrywa, kiedy klawiatura jest widoczna i przesunie się nad klawiaturą w rozsądnej odległości. Jest to idealne rozwiązanie, ponieważ jest niezależne od Twojego UIViewController
. Każda niezbędna rzecz odbywa się w ramach wyżej wymienionej klasy. Dzięki Michael Tyson et all.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-19 13:13:22
Poniżej szybka wersja odpowiedzi Amagrammera. Również odmiana wykorzystująca Zdarzenie UIKeyboardWillShowNotification, ponieważ musiałem znać rozmiar klawiatur przed przesunięciem widoku z drogi.
var keyboardHeight:CGFloat = 0
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillChange:", name: UIKeyboardWillShowNotification, object: nil)
}
func textFieldDidBeginEditing(textField: UITextField) {
//keyboardWillChange (below) is used instead of textFieldDidBeginEditing because textFieldDidBeginEditing
//is called before the UIKeyboardWillShowNotification necessary to determine the keyboard height.
}
func textFieldDidEndEditing(textField: UITextField) {
animateTextField(false)
}
func animateTextField(textFieldUp:Bool) {
let movementDistance:CGFloat = keyboardHeight
let movementDuration = 0.3
let movement:CGFloat = (textFieldUp ? -movementDistance : movementDistance)
UIView.beginAnimations("anim", context: nil)
UIView.setAnimationBeginsFromCurrentState(true)
UIView.setAnimationDuration(movementDuration)
self.view.frame = CGRectOffset(self.view.frame, 0, movement)
UIView.commitAnimations()
}
func keyboardWillChange(notification:NSNotification) {
let keyboardRect:CGRect = ((notification.userInfo![UIKeyboardFrameEndUserInfoKey])?.CGRectValue)!
keyboardHeight = keyboardRect.height
animateTextField(true)
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-11-11 19:28:53
W edytowanie pól tekstowych bez zaciemniania (link martwy, oto link zwrotny: https://web.archive.org/web/20091123074029/http://acts-as-geek.blogspot.com/2009/11/editing-textfields-without-obscuring.html). pokazuje, jak przenieść istniejącą UIView
na UIScrollView
i przewijać ją automatycznie po pojawieniu się klawiatury.
Zaktualizowałem go trochę, aby obliczyć prawidłową wysokość dla UIScrollView
, gdy są kontrole (takie jak UITabBar
) poniżej UIScrollBar
. Zobacz post aktualizujący uiview .
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-18 22:45:01
Oto rozwiązanie za pomocą Xcode5, iOS7:
Użyj bloków UITextfieldDelegate i animation.
Jest to prawie cały kod dla Viewcontrollera, ale chciałem dołączyć kod delegata dla tych, którzy nadal nie znają wzorca delegata (jak ja). Dodałem również kod, aby ukryć klawiaturę po dotknięciu z dala od widoku tekstu.
Możesz przesuwać widoki(przyciski, pola tekstowe itp.) tak wysoko, jak chcesz, tylko upewnij się, że umieścisz je z powrotem na swoim miejscu (+100 później -100).
@interface ViewController () <UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *MyTextField;
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.MyTextField.delegate = self;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"text began editing");
CGPoint MyPoint = self.MyTextField.center;
[UIView animateWithDuration:0.3
animations:^{
self.MyTextField.center = CGPointMake(MyPoint.x, MyPoint.y - 100);
}];
}
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"text ENDED editing");
CGPoint MyPoint = self.MyTextField.center;
[UIView animateWithDuration:0.3
animations:^{
self.MyTextField.center = CGPointMake(MyPoint.x, MyPoint.y + 100);
}];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-06-12 01:14:41
Myślę, że jednym ze sposobów byłoby przeniesienie pozycji całego widoku z (x,y) do (x,y-keybaardHeight) po kliknięciu pola tekstowego i odłożenie go z powrotem, gdy klawiatura zostanie odrzucona, może to wyglądać trochę dziwnie, ponieważ Widok właśnie pojawia się (może nie byłoby źle, jeśli go animujesz).
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
CGRect frame=self.view.frame;
frame.origin=CGPointMake(x...//set point here
self.view.frame=frame;
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2009-08-07 22:59:56
Oprócz rozwiązania Amagrammer, jeśli używasz cocos2d w trybie portretowym zmień tę linię:
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
Do tego:
[CCDirector sharedDirector].openGLView.frame = CGRectOffset([CCDirector sharedDirector].openGLView.frame, movement, 0);
Jeśli używasz cocos2d w trybie poziomym, dokonaj powyższej zmiany i przełącz up
wartości w textFieldDidBeginEditing:
i textFieldDidEndEditing:
- (void)textFieldDidBeginEditing:(UITextField *)textField {
[self animateTextField:textField up:NO];
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self animateTextField:textField up:YES];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-08 20:04:16
Miałem ten sam problem i uznałem GTKeyboardHelper za łatwe wyjście.
Po przeciągnięciu i upuszczeniu frameworka w projekcie Dołącz plik nagłówkowy. Pobierz i otwórz przykładowy projekt, a następnie przeciągnij obiekt "Pomocnik klawiatury" z sekcji obiekty w xib do sekcji obiekty w kreatorze interfejsu projektu.
Przeciągnij i upuść wszystkie widoki, aby być dziećmi "pomocnika klawiatury".
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-04-25 16:52:22
Jak poradzić sobie z sytuacją, gdy klawiatura jest podniesiona, a ramka została zmieniona za pomocą animacji i przewijana, aby pole tekstowe nie było zakryte, stamtąd po wybraniu innego pola tekstowego (nadal edytując pierwsze pole tekstowe) jak nie odtwarzać animacji ponownie i po prostu przewijać nieco dalej, jeśli to konieczne? Problem polega na odtworzeniu całej animacji, gdy nie jest to konieczne. Dzięki
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-05-30 21:41:31
Drag and drop framework, którego używam w moich projektach. Obsługuje automatyczne zwolnienie po dotknięciu poza osobą udzielającą pierwszej pomocy lub po przewinięciu.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-19 13:12:15
Proszę spojrzeć na mój komentarz w tym:
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:09:33
Po prostu przesuń widok w górę iw dół w razie potrzeby:
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.currentTextField = nil;
[self animateTextField: textField up: NO];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[self.currentTextField resignFirstResponder];
return YES;
}
- (void) animateTextField:(UITextField*) textField up:(BOOL)up {
const int movementDistance = 80; // tweak as needed
const float movementDuration = 0.3f; // tweak as needed
int movement = (up ? -movementDistance : movementDistance);
[UIView animateWithDuration:movementDuration animations:^{
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
}];
}
Nie zapomnij ustawić self
jako UITextFieldDelegate
i jako rzeczywiste pole tekstowe delegate
.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-01-14 13:37:45
Mam coś jeszcze, Jeśli chcesz. Chodzi o to, że chcesz ustawić środek widoku UIView na edytowanym polu tekstowym.
Przed tym, musisz zapisać INITIAL_CENTER , jako CGPoint , od siebie.widok.centrum i twój INITIAL_VIEW jako CGRect od siebie.widok.frame in a const property.
Możesz utworzyć taką metodę:
- (void) centerOn: (CGRect) fieldFrame {
// Set up the center by taking the original view center
CGPoint center = CGPointMake(INITIAL_CENTER.x,
INITIAL_CENTER.y - ((fieldFrame.origin.y + fieldFrame.size.height/2) - INITIAL_CENTER.y));
[UIView beginAnimations:@"centerViewOnField" context:nil];
[UIView setAnimationDuration:0.50];
if (CGRectEqualToRect(fieldFrame,INITIAL_VIEW)) {
self.view.frame = INITIAL_VIEW;
[self.view setCenter:INITIAL_CENTER];
} else {
[self.view setCenter:center];
}
[UIView commitAnimations];
}
Następnie, na Twoim UITextFieldDelegate , Musisz zadzwonić centerOn: (CGRect) w następujących metodach:
TextFieldDidBeginEditing: (UITextField*) z, jako parametrem, ramką pola tekstowego, na którym chcesz się wyśrodkować.
I musisz to wywołać w programie obsługi zdarzeń, gdzie zamykasz klawiaturę,
TextFieldDidEndEditing:(UITextField*) może być jednym ze sposobów, aby to zrobić, umieszczając INITIAL_VIEW jako parametr centerOn: (CGRect).
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-27 13:52:17
Wierzę, że w nowszych wersjach iOS (6.1+, być może nawet wcześniej), podstawowy widok, przynajmniej dla UITableView, automatycznie kurczy się, gdy pojawi się klawiatura. Wystarczy więc, aby pole tekstowe było widoczne w tym widoku. W init
:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
Wtedy:
- (void)keyboardWasShown:(NSNotification*)notification
{
// Scroll the text field into view so it's not under the keyboard.
CGRect rect = [self.tableView convertRect:inputView.bounds fromView:inputView];
[self.tableView scrollRectToVisible:rect animated:YES];
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-11-19 18:25:36
//
// ViewController.swift
// Shift Keyboard Example
//
// Created by Zulwiyoza Putra on 11/23/16.
// Copyright © 2016 Zulwiyoza Putra. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
//connecting textfield from storyboard
@IBOutlet weak var textField: UITextField!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
subscribeToKeyboardNotifications()
}
override func viewDidAppear(_ animated: Bool) {
self.textField.delegate = self
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
unsubscribeFromKeyboardNotifications()
}
//Hide keyboard after finished editing
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
//Setup view before keyboard appeared
func keyboardWillAppear(_ notification:Notification) {
view.frame.origin.y = 0 - getKeyboardHeight(notification)
}
//Setup view before keyboard disappeared
func keyboardWillDisappear(_ notification: Notification) {
view.frame.origin.y = 0
}
//Getting keyboard height
func getKeyboardHeight(_ notification:Notification) -> CGFloat {
let userInfo = notification.userInfo
let keyboardSize = userInfo![UIKeyboardFrameEndUserInfoKey] as! NSValue // of CGRect
return keyboardSize.cgRectValue.height
}
//Subscribing to notifications to execute functions
func subscribeToKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillAppear(_:)), name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillDisappear(_:)), name: .UIKeyboardWillHide, object: nil)
}
//Unsubscribing from notifications
func unsubscribeFromKeyboardNotifications() {
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillHide, object: nil)
}
}
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-24 06:57:27