如何在iphone应用程序中滑动屏幕以查看我们在文本字段中输入的数据

如何在iphone应用程序中滑动屏幕以查看我们在文本字段中输入的数据,iphone,ipad,uitextfield,Iphone,Ipad,Uitextfield,可能重复: 当我们通常在文本字段中输入数据时,键盘会出现,它会隐藏我们在字段中输入的数据,因此是否有任何方式可以使屏幕向上滑动,以便我们可以看到在字段中输入的数据。有通知()告诉您键盘即将出现或消失,您可以使用这些来触发移动视图的代码。移动视图有不同的方法--您可以自己移动视图,随意调整视图的位置;您可以将它们全部放在一个视图中,这样您只需移动容器;或者,您可以将它们嵌入到滚动视图中,只需调整滚动视图的内容偏移量 请参阅苹果公司的文档,特别是名为。这里也有示例代码,它运行得很好。试试这段代码

可能重复:

当我们通常在文本字段中输入数据时,键盘会出现,它会隐藏我们在字段中输入的数据,因此是否有任何方式可以使屏幕向上滑动,以便我们可以看到在字段中输入的数据。

有通知()告诉您键盘即将出现或消失,您可以使用这些来触发移动视图的代码。移动视图有不同的方法--您可以自己移动视图,随意调整视图的位置;您可以将它们全部放在一个视图中,这样您只需移动容器;或者,您可以将它们嵌入到滚动视图中,只需调整滚动视图的内容偏移量

请参阅苹果公司的文档,特别是名为。这里也有示例代码,它运行得很好。

试试这段代码

 -(void)setViewMovedUp:(BOOL)movedUp
 {
 [UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3]; // if you want to slide up the view

CGRect rect = self.view.frame;
if (movedUp)
{
    rect.origin.y -= moveKeyboard;
}
else
{
    rect.origin.y += moveKeyboard;
}
self.view.frame = rect;
[UIView commitAnimations];
}

  -(void)keyboardWillShow
 {
// Animate the current view out of the way
if (self.view.frame.origin.y >= 0)
{
    [self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
    [self setViewMovedUp:NO];
}
 }


 -(void)keyboardWillHide
 {
if (self.view.frame.origin.y >= 0)
{
    [self setViewMovedUp:YES];
}
else if (self.view.frame.origin.y < 0)
{
    [self setViewMovedUp:NO];
}
}


 - (void)viewWillAppear:(BOOL)animated
 {
[super viewWillAppear:animated];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow)
                                             name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide)
                                             name:UIKeyboardWillHideNotification object:nil];
 }
 - (void)viewWillDisappear:(BOOL)animated
 {
[super viewWillDisappear:animated];
// unregister for keyboard notifications while not visible.
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
 }
-(void)setViewMovedUp:(BOOL)movedUp
{
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationDuration:0.3];//如果要向上滑动视图
CGRect rect=self.view.frame;
if(movedUp)
{
rect.origin.y-=移动键盘;
}
其他的
{
rect.origin.y+=移动键盘;
}
self.view.frame=rect;
[UIView委员会];
}
-(无效)键盘将显示
{
//设置当前视图的动画,使其不碍事
if(self.view.frame.origin.y>=0)
{
[self-setViewMovedUp:是];
}
else if(self.view.frame.origin.y<0)
{
[self-setViewMovedUp:否];
}
}
-(无效)键盘将隐藏
{
if(self.view.frame.origin.y>=0)
{
[self-setViewMovedUp:是];
}
else if(self.view.frame.origin.y<0)
{
[self-setViewMovedUp:否];
}
}
-(无效)视图将显示:(BOOL)动画
{
[超级视图将显示:动画];
//注册键盘通知
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(键盘将显示)
名称:UIKeyboardWillShowNotification对象:nil];
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(keyboardWillHide)
名称:UIKeyboardWillHideNotification对象:nil];
}
-(无效)视图将消失:(BOOL)已设置动画
{
[超级视图将消失:动画];
//在不可见时注销键盘通知。
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification对象:nil];
[[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification对象:nil];
}
编辑:移动键盘是浮动的。根据需要设置其值。

可能重复:,