一个view的问题

ccnyou 2012-04-12 02:30:53
由于虚拟键盘的会占据原因,如果我的一个textField在屏幕下方就看不到了。我的想法是,在
- (void)textFieldDidBeginEditing:(UITextField *)textField 里面创建一个view,里面再在上面创建一个新的textView,让用户在textField输入,输入完后我在吧结果送到textField 。但是当我创建一个view并addSubView后,发现下面的那个View还是活动的,就是用户可能点击到下面的空间,应该怎么屏蔽呢?最好可以让新的view是半透明的,就是可以看到后面的view的内容但是不能操作。
效果如图,label是后面的view的空间,不希望用户可以操作,上面ceshi是
textView
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccnyou 2012-04-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

不用这么麻烦的。只要注册两个通知,当键盘出现的时候向上移动view(保证UITextField不被遮挡),键盘消失的时候向下移动view至原位置。
C/C++ code

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[NSNotificationCenter defaultCente……
[/Quote]

这是一个不错的做法,事实上我是想封装一个类,以后有这种情况时不用那么麻烦,可以直接用。所以我还是想问为什么我那种做法不行?
workman918 2012-04-13
  • 打赏
  • 举报
回复
我没有积分发帖,搭车求下ocf、epub、mobi格式电子书的制作方法和软件介绍
  • 打赏
  • 举报
回复
网上有很多解决方法的。用notification。可以用scrollview 也可以用view的annimation
Gil 2012-04-12
  • 打赏
  • 举报
回复
不用这么麻烦的。只要注册两个通知,当键盘出现的时候向上移动view(保证UITextField不被遮挡),键盘消失的时候向下移动view至原位置。

-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[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:YES];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillShow:(NSNotification *)aNotification
{
NSTimeInterval animationDuration =
[[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.center = CGPointMake(160, 180);
[UIView commitAnimations];
}

- (void)keyboardWillHide:(NSNotification *)aNotification
{
NSTimeInterval animationDuration =
[[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.center = CGPointMake(160, 240);
[UIView commitAnimations];
}

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧