iphone:在视图中滚动
我想问一个基本的iphone问题。我在iPhone视图中有很多文本字段,当我点击输入文本字段时,键盘会显示并隐藏其他文本字段。我想使父视图可滚动。请给我看一下示例代码好吗iphone:在视图中滚动,iphone,view,uiscrollview,uiscrollviewdelegate,Iphone,View,Uiscrollview,Uiscrollviewdelegate,我想问一个基本的iphone问题。我在iPhone视图中有很多文本字段,当我点击输入文本字段时,键盘会显示并隐藏其他文本字段。我想使父视图可滚动。请给我看一下示例代码好吗 非常感谢您可以收听键盘上下提示。并将视图移动到键盘高度的正上方 在视图中将出现方法: NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(keyboardWillShow
非常感谢您可以收听键盘上下提示。并将视图移动到键盘高度的正上方 在
视图中将出现方法:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
在视图中将消失方法中:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
然后采用上述方法调整杆的位置:
-(void) keyboardWillShow:(NSNotification *) note
{
CGRect r = bar.frame, t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
r.origin.y -= t.size.height;
bar.frame = r;
}
-(void) keyboardWillHide:(NSNotification *) note
{
CGRect r = bar.frame, t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
r.origin.y += t.size.height;
bar.frame = r;
}
您可以监听键盘上下的通知。并将视图移动到键盘高度的正上方
在视图中将出现方法:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
在视图中将消失方法中:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
然后采用上述方法调整杆的位置:
-(void) keyboardWillShow:(NSNotification *) note
{
CGRect r = bar.frame, t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
r.origin.y -= t.size.height;
bar.frame = r;
}
-(void) keyboardWillHide:(NSNotification *) note
{
CGRect r = bar.frame, t;
[[note.userInfo valueForKey:UIKeyboardBoundsUserInfoKey] getValue: &t];
r.origin.y += t.size.height;
bar.frame = r;
}
这会给你一个想法
这会给你一个主意
如果parentview是UIScrollView,请尝试类似于in-textfield delegate的方法
- (BOOL) textFieldShouldReturn:(UITextField *)theTextField
{
if (theTextField == textFieldName) {
[scroll scrollRectToVisible:CGRectMake(0, 160, 280, 440) animated:YES];//choose the rect accordingly.
}
return YES;
}
-(BOOL)文本字段应返回:(UITextField*)文本字段
{
如果(theTextField==textFieldName){
[滚动scroll-scrollRectToVisible:CGRectMake(0、160、280、440)动画:是];//相应地选择矩形。
}
返回YES;
}
如果parentview是UIScrollView,请尝试类似于in-textfield delegate的操作
- (BOOL) textFieldShouldReturn:(UITextField *)theTextField
{
if (theTextField == textFieldName) {
[scroll scrollRectToVisible:CGRectMake(0, 160, 280, 440) animated:YES];//choose the rect accordingly.
}
return YES;
}
-(BOOL)文本字段应返回:(UITextField*)文本字段
{
如果(theTextField==textFieldName){
[滚动scroll-scrollRectToVisible:CGRectMake(0、160、280、440)动画:是];//相应地选择矩形。
}
返回YES;
}
谢谢,但在这种情况下,视图无法滚动。如果我想上下滚动查看其他文本字段,我不能用这种方式。有其他解决方案吗?尝试将所有视图放在UIScrollView中(这将称为容器视图),然后在self.view addsubview中添加UIScrollView。iMyUIScrollView。。。如果有任何困难,请告诉我…我将所有文本字段添加到UIScrollView,该ScrollView是UIView(MyViewController)的子视图。但我仍然无法滚动视图中的许多文本字段。我想我正在使用UIScrollView进行操作,是吗?现在,您可以在键盘上看到您的视图了吗?使用apple示例代码处理scrollview的“谢谢”,但在这种情况下,视图无法滚动。如果我想上下滚动查看其他文本字段,我不能用这种方式。有其他解决方案吗?尝试将所有视图放在UIScrollView中(这将称为容器视图),然后在self.view addsubview中添加UIScrollView。iMyUIScrollView。。。如果有任何困难,请告诉我…我将所有文本字段添加到UIScrollView,该ScrollView是UIView(MyViewController)的子视图。但我仍然无法滚动视图中的许多文本字段。我想我是在用UIScrollView操作,对吗?现在,你能在键盘上看到你的视图吗?使用苹果的示例代码来处理scrollview的