我第一次使用静态分析器并且很难找出箭头。在查看了一些关于 SO 的类似问题后,我认为问题在于 CGSize 大小为 nil 值,但我不完全确定它是如何工作的。
这是代码:
- (void)keyboardDidShow:(NSNotification*)notification {
CGSize size = CGSizeMake(0, 0);
size = [self keyboardSize:notification];
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
detailTableView.frame = CGRectMake(detailTableView.frame.origin.x, detailTableView.frame.origin.y,
detailTableView.frame.size.width, kTableViewMovableHeight + kTableViewDefaultHeight - size.height
);
//detailTableView.scrollEnabled = YES;
}
}
- (CGSize)keyboardSize:(NSNotification *)aNotification {
NSDictionary *info = [aNotification userInfo];
NSValue *beginValue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
CGSize keyboardSize;
UIDeviceOrientation _screenOrientation = orientation;
if ([UIKeyboardDidShowNotification isEqualToString:[aNotification name]]) {
if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize = [beginValue CGRectValue].size;
} else {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
}
} else if ([UIKeyboardWillHideNotification isEqualToString:[aNotification name]]) {
if (_screenOrientation == orientation) {
if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize = [beginValue CGRectValue].size;
} else {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
}
// rotated
} else if (UIDeviceOrientationIsPortrait(orientation)) {
keyboardSize.height = [beginValue CGRectValue].size.width;
keyboardSize.width = [beginValue CGRectValue].size.height;
} else {
keyboardSize = [beginValue CGRectValue].size;
}
}
return keyboardSize;
}