[英]iPad keyboard hiding textfield
這是鍵盤隱藏文本字段的非常普遍的問題。 SO上也為此發布了許多解決方案。
因此,當前我指的是以下帖子 ,該帖子在iPad縱向模式下運行良好,但在iPad橫向模式下,視圖向左滑動,因為我希望視圖向上移動。
- (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];
}
由於iPad本身為鍵盤提供了諸如“ Undock”和“ Split”之類的不錯選項,因此通常我們不需要安排文本字段。 盡管考慮到您是否有問題,是否需要根據該動畫文本字段框架使用[[UIDevice currentDevice] orientation]
檢查設備當前方向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.