【发布时间】:2013-12-20 03:01:40
【问题描述】:
我正在修复我的 UITextView,使其不显示在键盘下方,而是将其调整为正确的约束。这可能是一个愚蠢的问题,除了这个愚蠢的问题,很可能还有一个简单的解决方法,但我需要将当前为黑色的视图着色为whiteColor - 似乎我在正确的行上空白这样做的代码。我已经搜索了 Stack Overflow 和 Google 一段时间,但我没有找到任何不返回错误的代码。
键盘后面的黑色矩形。
- (void)keyboardDidShow:(NSNotification *)aNotification {
NSDictionary* info = [aNotification userInfo];
CGRect kbRect = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
kbRect = [[self view] convertRect:kbRect fromView:nil];
CGSize kbSize = kbRect.size;
CGRect aRect = self.view.frame;
/* This should work, but doesn't quite qet the job done */
// UIEdgeInsets insets = self.textView.contentInset;
// insets.bottom = kbSize.height;
// self.textView.contentInset = insets;
//
// insets = self.textView.scrollIndicatorInsets;
// insets.bottom = kbSize.height;
// self.textView.scrollIndicatorInsets = insets;
/* Instead, we just adjust the frame of the uitextview */
aRect.size.height -= kbSize.height + VERTICAL_KEYRBOARD_MARGIN;
self.companyTextField.frame = aRect;
// If active text field is hidden by keyboard, scroll it so it's visible
// Your application might not need or want this behavior.
if (!CGRectContainsPoint(aRect, self.companyTextField.frame.origin) ) {
CGPoint scrollPoint = CGPointMake(0.0, self.companyTextField.frame.origin.y - kbSize.height);
[self.companyTextField setContentOffset:scrollPoint animated:YES];
}
}
【问题讨论】:
-
将容器视图的背景颜色设置为白色。 (主窗口视图)以及滚动视图背景颜色为白色。或者,如果您在它后面有另一个视图,请将其设置为白色。通过查看图像,您似乎实际上是在调整视图的大小,而不是 textview。
-
通常 self.view 颜色为黑色,而您使用的是 scrollview。因为我们不太清楚哪个视图是黑色的。将 self.view 的颜色设置为红色,将滚动视图的颜色设置为蓝色。并检查以便我们可以轻松知道哪个视图具有黑色背景色,以便我们轻松修复
-
@CharanGiri 设置
self.view的背景颜色似乎符合预期,但是我不明白如何设置scrollview的背景颜色。 SelfViewRedScreenshot.png
标签: ios objective-c uitextview uikeyboard cgrect