我正在尝试创建一个用户可以输入文本和表情符号的UITextView。
我的光标显示有问题。
我的目标是在选择表情符号时隐藏光标(键盘隐藏)。
我知道可以这样做,因为名为“Kakao Story”的应用程序具有此功能。
有人有解决方案吗?感谢。
答案 0 :(得分:0)
我找到了一种隐藏keyboardView的方法来实现我的目的。
这是代码
+ (void)hideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:YES];
}
}
}
}
+ (void)unhideKeyboard
{
for (UIWindow *aWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *possibleKeyboard in [aWindow subviews]) {
UIView *keyboardView = [self getPeripheralHostViewFromView:possibleKeyboard];
if (keyboardView) {
[keyboardView setHidden:NO];
}
}
}
}
+ (UIView *)getPeripheralHostViewFromView:(UIView *)superView
{
if ([superView.description hasPrefix:@"<UIPeripheralHostView"]) {
return superView;
}else if([superView.description hasPrefix:@"<UIKBInputBackdropView"]) {
return superView.superview;
}else {
for (UIView *subView in superView.subviews) {
UIView *keyboardHostView = [self getPeripheralHostViewFromView:subView];
if (keyboardHostView) {
return keyboardHostView;
}
}
}
return nil;
}