[英]ios keyboard clickable but not visible
我正在制作一個允許用戶提問的應用程序。 在我的addQuestion類中,我有一個UITextView,用戶可以在其中寫下他們的問題。
我的問題是,有時候我的iPhone上的鍵盤是看不見的(並非每次都發生這種情況-僅在我第一次打開該應用程序時-有時甚至可以立即使用)。 奇怪的是,我仍然可以按鍵盤上的鍵,並根據鍵盤可見的位置鍵入響應。 問題僅在於可見性(我嘗試移動UITextView以便不會阻塞鍵盤)。 大約20或25秒后,鍵盤出現。
我還使用了蘋果推薦的故障排除方法:
for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
NSLog(@"isKeyWindow = %d window level = %.1f frame = %@ class = %@\n",
window.isKeyWindow, window.windowLevel,
NSStringFromCGRect(window.frame), window.class.description);
}
但是沒有覆蓋UITextEffectsWindow的自定義窗口
它輸出:
isKeyWindow = 1 window level = 0.0 frame = {{0, 0}, {375, 667}} class = UIWindow**
isKeyWindow = 0 window level = 10.0 frame = {{0, 0}, {375, 667}} class = UITextEffectsWindow**
當它最終工作並且鍵盤可見時:
isKeyWindow = 1 window level = 0.0 frame = {{0, 0}, {375, 667}} class = UIWindow
isKeyWindow = 0 window level = 1.0 frame = {{0, 0}, {375, 667}} class = UITextEffectsWindow
也許與窗口級別為10.0有關嗎? 當鍵盤最終顯示時,窗口級別為1.0 ...
這是.m類,以獲取更多信息
@interface addQuestion () <UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *questionText;
@property (strong, nonatomic) NSDictionary *dictionary;
@end
@implementation addQuestion
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self.questionText becomeFirstResponder];
self.questionText.delegate = self;
self.questionText.text = @"Ask a good yes or no question!";
self.questionText.textColor = [UIColor lightGrayColor];
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"Post" style:UIBarButtonItemStylePlain target:self action:@selector(posted)];
self.navigationItem.rightBarButtonItem = anotherButton;
// for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
// NSLog(@"isKeyWindow = %d window level = %.1f frame = %@ class = %@\n",
// window.isKeyWindow, window.windowLevel,
// NSStringFromCGRect(window.frame), window.class.description);
// }
}
- (void)textViewDidChangeSelection:(UITextView *)textView{
if ([textView.text isEqualToString:@"Ask a good yes or no question!"] && [textView.textColor isEqual:[UIColor lightGrayColor]])[textView setSelectedRange:NSMakeRange(0, 0)];
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
[textView setSelectedRange:NSMakeRange(0, 0)];
}
- (void)textViewDidChange:(UITextView *)textView
{
if (textView.text.length != 0 && [[textView.text substringFromIndex:1] isEqualToString:@"Ask a good yes or no question!"] && [textView.textColor isEqual:[UIColor lightGrayColor]]){
textView.text = [textView.text substringToIndex:1];
textView.textColor = [UIColor blackColor]; //optional
self.navigationItem.leftBarButtonItem.enabled=YES;
}
else if(textView.text.length == 0){
self.navigationItem.leftBarButtonItem.enabled=NO;
textView.text = @"Ask a good yes or no question!";
textView.textColor = [UIColor lightGrayColor];
[textView setSelectedRange:NSMakeRange(0, 0)];
}
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
if ([textView.text isEqualToString:@""]) {
textView.text = @"Ask a good yes or no question!";
textView.textColor = [UIColor lightGrayColor]; //optional
}
//[textView resignFirstResponder];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
if (text.length > 1 && [textView.text isEqualToString:@"Ask a good yes or no question!"]) {
textView.text = @"";
textView.textColor = [UIColor blackColor];
}
if([[textView text] length] > 140){
return NO;
} else {
return YES;
}
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
@end
[self.questionText becomeFirstResponder];
remove this
我的問題是我嘗試在后台線程中進行篩選(在NSURLSession進行回調之后)。
我應該做的是確保在主線程中調用了segue。
dispatch_async(dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"proceed" sender:self];
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.