iphone:在视图中滚动 [英] iphone: scroll in a view

查看:136
本文介绍了iphone:在视图中滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个基本的iphone问题。我在iPhone视图中有很多TextFields,当我点击在TextField中输入时,键盘会显示并隐藏其他TextField。我想使父视图可滚动。你能告诉我示例代码吗?

I would like to ask a basic iphone question. I have many TextFields in iPhone view, when I tap to input in a TextField, the Keyboard shows up and hide other TextField. I would like to make the parent view scrollable. Would you please show me the example code?

非常感谢

推荐答案

您可以收听键盘上下通知。并将您的视图移动到键盘高度之上。

You can listen for the keyboard up and down notification. and move your view just above height of keyboard.

ViewWillAppear 方法中:

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

ViewWillDisAppear 方法中:

  [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil]; 

然后使用上面提到的方法来调整条形图的位置:

And then have methods referred to above to adjust the position of the bar:

-(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;
    }

这篇关于iphone:在视图中滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆