我正在使用故事板开发一个iPad应用程序。对于我的iPad应用程序,我需要在一个屏幕上显示4 UICollectionView
。但是我没有足够的空间来显示所有4 {{1}所以我需要向视图控制器添加一个滚动视图,并在collectionView中的scrollview.Each单元格内显示CollectionViews,所有集合视图都有一个textfield.But如果出现键盘,则第3个CollectionView和第4个CollectionView躲在键盘后面。所以我需要做的是在键盘出现时将CollectionViews和我的视图放在滚动视图中。需要有关此的指导。
感谢。
答案 0 :(得分:0)
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardIsShown:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:)name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardIsShown:(NSNotification*)notification
{
NSDictionary* info = [notification userInfo];
CGSize keyboardSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
//Adjust your scrollview frame by reducing the height by keyboardSize.Height
}
- (void)keyboardWillBeHidden:(NSNotification*)notification
{
// Set the scrollview frame back to normal.
}
答案 1 :(得分:0)
您需要使用键盘通知。一个例子可能是这样的:
在viewDidLoad
:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil]; //This gets triggered when the keyboard comes up.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil]; // This gets triggered when the keyboard goes down.
在代码中的某处,您可以实现处理scrollView的方法,如下所示:
-(void)keyboardWillShow:(NSNotification *)notification {
// Code to move the UIScrollView up when the keyboard comes up
}
-(void)keyboardWillHide:(NSNotification *)notification {
// Code to move the UIScrollView down when the keyboard goes down.
}
修改强>
这在 tutorial
中有明确解释