字段在我看來,我想在鍵盤出現的時候將文本視圖向上移動,當我在第6,7,8號開始輸入文本時。僅限文本字段。如何在鍵盤出現時移動底部的textFields?
0
A
回答
0
我試過解決方案,你的問題,我只是得到。
#define kOFFSET_FOR_KEYBOARD 80.0
@interface ViewController()
{
NSInteger tagTF;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)setMovedUp:(BOOL)movedUP
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if(movedUP)
{
rect.origin.y -= kOFFSET_FOR_KEYBOARD;
rect.size.height += kOFFSET_FOR_KEYBOARD;
}
else{
rect.origin.y += kOFFSET_FOR_KEYBOARD;
rect.size.height -= kOFFSET_FOR_KEYBOARD;
}
self.view.frame = rect;
[UIView commitAnimations];
}
#pragma mark - UITextFieldDelegate Methods
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
tagTF = textField.tag;
if(textField.tag>=6)
{
if(self.view.frame.origin.y >= 0)
{
[self setMovedUp:YES];
}
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(textField.tag>=6)
{
[self setMovedUp:NO];
}
[textField resignFirstResponder];
return YES;
}
從我上面的回答我設置文本框的標籤從1到8.It完美的作品你want.Please設置文本框的委託。
+0
非常感謝你Ruchira蘭達納它爲我工作。 – user5575941
0
我有一個廣泛的博客文章,解釋如何做到這一點:
Shifting views to make room for the keyboard
它的要點是添加通知處理程序鍵盤將顯示和鍵盤會隱藏通知。在這些處理程序中,您可以獲得鍵盤的高度,然後進行一些數學計算,以確定您需要將該字段向上移動,以便鍵盤無法覆蓋它。然後,您將視圖控制器的視圖移到足以保持視野暴露的位置。
它變得複雜多了,但是這涵蓋的所有博客文章(這是a larger blog post on animating random shapes包括鍵盤技術的工作示例部分。)
0
0
here是由蘋果公司關於處理鍵盤的官方文檔。
0
- (BOOL) textFieldShouldBeginEditing:(UITextField *)textField {
CGRect frame = self.view.frame;
Float y = frame.origin.y - 70;
frame.origin.y = y;
self.view.frame = frame;
return YES;
}
- (void) textFieldDidEndEditing:(UITextField *)textField{
CGRect frame = self.view.frame;
Float y = frame.origin.y + 70;
frame.origin.y = y;
self.view.frame = frame;
}
如果有變化的y值(如70,80,......)在textFieldShouldBeginEditing方法,並增加相同的值,在textFieldDidEndEditing方法Y。
試試這個代碼。
相關問題
- 1. 如何在鍵盤出現在內部時移動視圖ConstraintLayout
- 2. 如何移動鍵盤經過TextFields時查看?
- 3. 當iPhone鍵盤彈出時,HTML底部textarea移動得太高
- 4. 鍵盤在textfields的方式如何向上移動視圖
- 5. 鍵盤出現時底部對話框片段不能滾動
- 6. 當鍵盤出現導致崩潰時滾動到底部
- 7. 當鍵盤出現時滾動到底部
- 8. 如何移除在onCreate時自動出現的鍵盤?
- 9. 鍵盤出現時向上移動UITextField
- 10. 鍵盤出現時移動UIView
- 11. 當鍵盤出現時移動視圖
- 12. 鍵盤出現時移動UIView
- 13. 如何在出現鍵盤時向上移動UIView?
- 14. 鍵盤下的Textfields
- 15. 當鍵盤出現時保持ListView的底部元素可見
- 16. 在xamarin中移動時形成鍵盤出現時的android
- 17. 當iPad出現鍵盤時如何移動視圖?
- 18. 當鍵盤出現時,如何使CCTextFieldTTF向上移動:Cocos2d-x
- 19. 當鍵盤打開時底部按鈕向上移動
- 20. 當軟鍵盤出現在Android中時,將ScrollView滾動到底部?
- 21. 當軟鍵盤出現時,只將底部向上推
- 22. 在鍵盤出現時發出移動視圖Swift
- 23. 使用swift時,textfield在鍵盤出現時向上移動
- 24. 鍵盤出現時移動視圖 - 僅在編輯時?
- 25. 帶有TextField的UITableView並在鍵盤出現時移動視圖
- 26. 如何在鍵盤出現或關閉時移動包含在UIViewController中的UIView?
- 27. 我想在鍵盤出現時向上移動按鈕
- 28. 當鍵盤出現時,UIPopoverController在iOS 7上奇怪地移動
- 29. UITextField在Swift中出現鍵盤時向上移動
- 30. iOS 8在出現鍵盤時向上移動UIView |問題
只是谷歌它之前發佈的問題,至少 – iAnurag
可以ü請給我一個鏈接 – user5575941