|
@@ -123,6 +123,11 @@
|
|
|
|
|
|
|
|
@property (nonatomic,strong) IBOutlet AMShipMap *shipMap;
|
|
@property (nonatomic,strong) IBOutlet AMShipMap *shipMap;
|
|
|
|
|
|
|
|
|
|
+@property (nonatomic,weak) UITableViewCell *editingCell;
|
|
|
|
|
+@property (nonatomic,strong) NSIndexPath *editingIndexPath;
|
|
|
|
|
+@property (nonatomic,weak) UITapGestureRecognizer *tap;
|
|
|
|
|
+@property (nonatomic,assign) BOOL showKeyboard;
|
|
|
|
|
+
|
|
|
@end
|
|
@end
|
|
|
|
|
|
|
|
@implementation DetailPageViewController
|
|
@implementation DetailPageViewController
|
|
@@ -187,6 +192,19 @@
|
|
|
[self configureTableView];
|
|
[self configureTableView];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
|
+ [super viewWillAppear:animated];
|
|
|
|
|
+ NSString *action_type = [self.params objectForKey:@"action_type"];
|
|
|
|
|
+ if ([action_type isEqualToString:@"Detail"]) { // 避免Tap与Tacking中Cell点击冲突
|
|
|
|
|
+ [self startListenKeyboard];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
|
+ [super viewWillDisappear:animated];
|
|
|
|
|
+ [self stopListenKeyboard];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
- (void)configureTableView {
|
|
- (void)configureTableView {
|
|
|
|
|
|
|
|
[self.table registerNib:[UINib nibWithNibName:@"AMCommHeadCell" bundle:nil] forCellReuseIdentifier:COMM_ID_HEAD];
|
|
[self.table registerNib:[UINib nibWithNibName:@"AMCommHeadCell" bundle:nil] forCellReuseIdentifier:COMM_ID_HEAD];
|
|
@@ -766,11 +784,33 @@
|
|
|
// return height;
|
|
// return height;
|
|
|
}
|
|
}
|
|
|
else if ([type isEqualToString:@"communication"]) {
|
|
else if ([type isEqualToString:@"communication"]) {
|
|
|
- NSInteger rowCount = [tableView numberOfRowsInSection:indexPath.section];
|
|
|
|
|
|
|
+ NSInteger rowCount = [self tableView:tableView numberOfRowsInSection:indexPath.section];
|
|
|
if (indexPath.row == 0) {
|
|
if (indexPath.row == 0) {
|
|
|
return 133.0f;
|
|
return 133.0f;
|
|
|
} else if (indexPath.row == rowCount - 1) {
|
|
} else if (indexPath.row == rowCount - 1) {
|
|
|
- return 200.0f;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
|
|
|
|
|
+ NSString *edit_content = [segment objectForKey:@"edit_content"];
|
|
|
|
|
+
|
|
|
|
|
+ CGFloat h = 40.0f; // 输入框高度,最小40
|
|
|
|
|
+ if (edit_content && edit_content.length > 0) {
|
|
|
|
|
+
|
|
|
|
|
+ AMCommEditCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"AMCommEditCell" owner:nil options:nil] objectAtIndex:0];
|
|
|
|
|
+
|
|
|
|
|
+ h = [cell heightForContent:edit_content withTableWidth:CGRectGetWidth(tableView.bounds)];
|
|
|
|
|
+
|
|
|
|
|
+ if (h < 40.0f) {
|
|
|
|
|
+ h = 40.0f;
|
|
|
|
|
+ } else if (h > 100.0f) { // 输入框高度,最大100
|
|
|
|
|
+ h = 100.0f;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } else {
|
|
|
|
|
+ h = 40.0f;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return 50.0f + h;
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
|
|
NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
|
|
NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
|
|
@@ -1507,6 +1547,98 @@
|
|
|
[self presentViewController:menuAlert animated:YES completion:nil];
|
|
[self presentViewController:menuAlert animated:YES completion:nil];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+#pragma mark - Keyboard
|
|
|
|
|
+
|
|
|
|
|
+- (void)startListenKeyboard {
|
|
|
|
|
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
|
+ // 键盘通知
|
|
|
|
|
+ [notificationCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
|
|
|
|
|
+ [notificationCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
|
|
|
|
|
+ [notificationCenter addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
|
|
|
|
|
+
|
|
|
|
|
+ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToHideKeyboard:)];
|
|
|
|
|
+ [self.view addGestureRecognizer:tap];
|
|
|
|
|
+ self.tap = tap;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)stopListenKeyboard {
|
|
|
|
|
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
|
+ [notificationCenter removeObserver:self];
|
|
|
|
|
+
|
|
|
|
|
+ [self.view removeGestureRecognizer:self.tap];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)tapToHideKeyboard:(UITapGestureRecognizer *)tap {
|
|
|
|
|
+ [self.view endEditing:YES];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**键盘隐藏*/
|
|
|
|
|
+- (void)keyboardWillHide:(NSNotification *)notification {
|
|
|
|
|
+ NSLog(@"keyboard hide");
|
|
|
|
|
+ self.showKeyboard = NO;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**键盘显示*/
|
|
|
|
|
+- (void)keyboardWillShow:(NSNotification *)notification {
|
|
|
|
|
+
|
|
|
|
|
+// NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
|
|
|
|
|
+// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
|
|
|
|
|
+// CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
+//
|
|
|
|
|
+// if (duration == 0) {
|
|
|
|
|
+// duration = 0.25;
|
|
|
|
|
+// }
|
|
|
|
|
+ NSLog(@"keyboard show");
|
|
|
|
|
+ self.showKeyboard = YES;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**在使用过程中切换键盘*/
|
|
|
|
|
+- (void)keyboardChangeFrame:(NSNotification *)notification {
|
|
|
|
|
+
|
|
|
|
|
+ NSLog(@"keyboard change frame");
|
|
|
|
|
+
|
|
|
|
|
+ NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
|
|
|
|
|
+// CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
|
|
|
|
|
+ CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
|
+
|
|
|
|
|
+ if (duration == 0) {
|
|
|
|
|
+ duration = 0.25;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ NSLayoutConstraint *bottom_constraint = nil;
|
|
|
|
|
+ for (NSLayoutConstraint *constraint in self.view.constraints) {
|
|
|
|
|
+ if ([constraint.identifier isEqualToString:@"table_bottom_constraint"]) {
|
|
|
|
|
+ bottom_constraint = constraint;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CGFloat tabBarY = CGRectGetMinY(self.tabBarController.tabBar.frame);
|
|
|
|
|
+
|
|
|
|
|
+ CGFloat offset = tabBarY - CGRectGetMinY(end);
|
|
|
|
|
+ if (offset < 0) {
|
|
|
|
|
+ offset = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (bottom_constraint) {
|
|
|
|
|
+ bottom_constraint.constant = offset;
|
|
|
|
|
+ [self.view layoutIfNeeded];
|
|
|
|
|
+
|
|
|
|
|
+ if (self.editingIndexPath) {
|
|
|
|
|
+ [self.table scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionNone animated:UITableViewRowAnimationNone];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ CGSize contentSize = self.table.contentSize;
|
|
|
|
|
+ CGPoint contentOffset = self.table.contentOffset;
|
|
|
|
|
+ offset = contentOffset.y - (contentSize.height - CGRectGetHeight(self.table.bounds));
|
|
|
|
|
+ if (offset > 0) {
|
|
|
|
|
+ contentOffset.y -= offset;
|
|
|
|
|
+ self.table.contentOffset = contentOffset;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#pragma mark - COMM Head Delegate
|
|
#pragma mark - COMM Head Delegate
|
|
|
|
|
|
|
|
- (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc {
|
|
- (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc {
|
|
@@ -1525,6 +1657,16 @@
|
|
|
self.content.segments = arr;
|
|
self.content.segments = arr;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+- (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField {
|
|
|
|
|
+ self.editingCell = cell;
|
|
|
|
|
+ self.editingIndexPath = [self.table indexPathForCell:cell];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)commHeadCell:(AMCommHeadCell *)cell didEndEditing:(UITextField *)textField {
|
|
|
|
|
+ self.editingCell = nil;
|
|
|
|
|
+ self.editingIndexPath = nil;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
#pragma mark - COMM Content Delegate
|
|
#pragma mark - COMM Content Delegate
|
|
|
|
|
|
|
|
- (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email {
|
|
- (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email {
|
|
@@ -1538,7 +1680,7 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email {
|
|
- (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email {
|
|
|
-
|
|
|
|
|
|
|
+ // 保存数据
|
|
|
NSIndexPath *indexPath = [self.table indexPathForCell:cell];
|
|
NSIndexPath *indexPath = [self.table indexPathForCell:cell];
|
|
|
|
|
|
|
|
NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
|
|
NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
|
|
@@ -1551,6 +1693,26 @@
|
|
|
NSMutableArray *arr = [self.content.segments mutableCopy];
|
|
NSMutableArray *arr = [self.content.segments mutableCopy];
|
|
|
[arr replaceObjectAtIndex:indexPath.section withObject:segment];
|
|
[arr replaceObjectAtIndex:indexPath.section withObject:segment];
|
|
|
self.content.segments = arr;
|
|
self.content.segments = arr;
|
|
|
|
|
+
|
|
|
|
|
+ // 调用 tableView 的 beginUpdates 和 endUpdates,重新计算 cell 的高度
|
|
|
|
|
+ [self.table beginUpdates];
|
|
|
|
|
+ [self.table endUpdates];
|
|
|
|
|
+
|
|
|
|
|
+ // 防止在输入的时候超出屏幕区域
|
|
|
|
|
+ CGRect frame = cell.frame;
|
|
|
|
|
+ if (CGRectGetMaxY(frame) > CGRectGetMaxY(self.table.bounds)) {
|
|
|
|
|
+ [self.table scrollRectToVisible:frame animated:NO];
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)commEditCell:(AMCommEditCell *)cell didBeginEditing:(UITextView *)textView {
|
|
|
|
|
+ self.editingCell = cell;
|
|
|
|
|
+ self.editingIndexPath = [self.table indexPathForCell:cell];
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+- (void)commEditCell:(AMCommEditCell *)cell didEndEditing:(UITextView *)textView {
|
|
|
|
|
+ self.editingCell = nil;
|
|
|
|
|
+ self.editingIndexPath = nil;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
@end
|