Ios 应用程序从后台返回时出现黑屏
我正在处理我的应用程序上一个棘手的错误。我有一个聊天视图控制器,可以处理键盘显示和隐藏。但奇怪的是,将应用程序放在后台时 这是进入后台之前的视图控制器(点击主页按钮) 这是从后台返回时的应用程序 如果我使用home(主页)按钮将应用程序放在后台,黑屏只会出现一秒钟,但如果我阻止手机,然后解锁,黑屏会一直存在 这就是我处理键盘的方式Ios 应用程序从后台返回时出现黑屏,ios,objective-c,iphone,Ios,Objective C,Iphone,我正在处理我的应用程序上一个棘手的错误。我有一个聊天视图控制器,可以处理键盘显示和隐藏。但奇怪的是,将应用程序放在后台时 这是进入后台之前的视图控制器(点击主页按钮) 这是从后台返回时的应用程序 如果我使用home(主页)按钮将应用程序放在后台,黑屏只会出现一秒钟,但如果我阻止手机,然后解锁,黑屏会一直存在 这就是我处理键盘的方式 - (void)keyboardWillShowWithRect:(CGRect)rect { //We adjust inverted insets bec
- (void)keyboardWillShowWithRect:(CGRect)rect
{
//We adjust inverted insets because tableview will be inverted
CGFloat displacementDistance = rect.size.height - self.composeBarView.bounds.size.height;
self.tableView.contentInset = UIEdgeInsetsMake(self.composeBarView.bounds.size.height, 0, displacementDistance, 0);
[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y - displacementDistance, self.view.frame.size.width, self.view.frame.size.height)];
}
- (void)keyboardWillDismissWithRect:(CGRect)rect
{
//We adjust inverted insets because tableview will be inverted
CGFloat displacementDistance = rect.size.height - self.composeBarView.bounds.size.height;
self.tableView.contentInset = UIEdgeInsetsMake(self.composeBarView.bounds.size.height, 0, 0, 0);
[self.view setFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y + displacementDistance, self.view.frame.size.width, self.view.frame.size.height)];
}
用于显示消息的tableView倒置,以便在底部显示第一条消息。我是这样做的:
- (void)setupTableView
{
self.tableView.delegate = self;
self.tableView.dataSource = self;
//We adjust inverted insets because tableview will be inverted
self.tableView.contentInset = UIEdgeInsetsMake(self.composeBarView.bounds.size.height, 0, 0, 0);
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 500.0;
self.tableView.sectionFooterHeight = 30.0;
self.tableView.showsVerticalScrollIndicator = NO;
[self.tableView registerNib:[UINib nibWithNibName:@"MessagesDateHeader" bundle:nil] forHeaderFooterViewReuseIdentifier:@"MessagesDateHeader"];
// Table View is inverted so we display last messages at the bottom instead of top
self.tableView.transform = CGAffineTransformMakeRotation(-M_PI);
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapOnTableView)];
tap.numberOfTapsRequired = 1;
[self.tableView addGestureRecognizer:tap];
}
此外,我还有self.definesPresentationContext=YES代码>设置为打开viewDidLoad
谁能告诉我发生了什么事
谢谢,我以前也有类似的问题。问题是当键盘根据其框架显示/消失时,调整tableView的大小。
我所做的是在tableView的底部和superView之间设置一个约束,然后随着键盘的出现/消失更改其常量
您可以使用listen toUIKeyboardWillChangeFrameNotification
并按如下方式处理它,而不是依赖于keyboardWillShowWithRect:
和keyboardWillDismissWithRect:
- (void) keyboardWillChangeFrame:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
CGRect keyboardFrameEnd = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
keyboardFrameEnd = [self.view convertRect:keyboardFrameEnd toView:nil];
[UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue]
delay:0.f
options:[userInfo[UIKeyboardAnimationCurveUserInfoKey] intValue] << 16
animations:^{
self.bottomConstraint.constant = CGRectGetHeight(self.view.frame) - keyboardFrameEnd.origin.y;
[self.view layoutIfNeeded];
} completion:nil];
}
-(无效)键盘将更改框架:(NSNotification*)通知{
NSDictionary*userInfo=[notification userInfo];
CGRect keyboardFrameEnd=[userInfo[UIKeyboardFrameEndUserInfoKey]CGRectValue];
keyboardFrameEnd=[self.view convertRect:keyboardFrameEnd-to-view:nil];
[UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey]doubleValue]
延迟:0.f
选项:[userInfo[UIKeyboardAnimationCurveUserInfo]intValue]尝试Xcode的视图调试功能。它应该向您显示它认为正在显示的视图及其关系。使用self.tableView.transform=CGAffineTransformMakeRotation(-M_PI)您希望实现什么
?这会旋转视图,但不会在后台更改应用程序前的消息顺序。请检查屏幕上是否存在关键字。对于关键字关闭方法或视图关闭,您可以使用[self.view endEditing:YES]@lufritz不,它不会改变顺序。我所做的是将tableview倒置,以模拟和倒置tableview。这不是问题,但我也会将该转换再次应用到我的单元格和部分标题,以避免看到倒置的内容。也许这是黑屏的原因。你为什么不迭代反转通过数据阵列进行转换?转换对cpu来说更为繁重,因此没有必要。