【发布时间】:2014-12-26 09:00:31
【问题描述】:
我是一名非常初级的移动程序员。我需要在键盘出现时上移文本视图。我遵循此move-uiview-up-when-the-keyboard-appears-in-ios 并且效果很好,但我有一个背景图像,我不想上移背景图像。所以所有文本框嵌入在名为 customView 的 UIView 中。我试图向上移动 customView 而不是 self.view 。当我开始进入第一个 textview 时,customView 向上移动。但是当我移动到第二个 textview 时,customview 向下移动到原始位置和 textView成为键盘下。当我开始进入第二个文本视图时,customView 需要保持向上移动。我非常感谢任何帮助!
@property (strong, nonatomic) IBOutlet UIView *customView;
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
return YES; }
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
[self.view endEditing:YES];
return YES; }
- (void)keyboardDidShow:(NSNotification *)notification
{
//Assign new frame to your view
[self.customView setFrame:CGRectMake(0,50,320,460)];
}
-(void)keyboardDidHide:(NSNotification *)notification
{
[self.customView setFrame:CGRectMake(0,193,320,460)];
}
【问题讨论】:
标签: ios objective-c uiview keyboard