diff --git a/iphone/Maps/Classes/MWMBookmarkDescriptionViewController.mm b/iphone/Maps/Classes/MWMBookmarkDescriptionViewController.mm index 753c9c8918..c783ab3cd3 100644 --- a/iphone/Maps/Classes/MWMBookmarkDescriptionViewController.mm +++ b/iphone/Maps/Classes/MWMBookmarkDescriptionViewController.mm @@ -157,6 +157,7 @@ typedef NS_ENUM(NSUInteger, BookmarkDescriptionState) - (void)cancelTap { + [self.textView resignFirstResponder]; if (self.manager.entity.isHTMLDescription) self.state = BookmarkDescriptionStateViewHTML; else @@ -168,12 +169,7 @@ typedef NS_ENUM(NSUInteger, BookmarkDescriptionState) MWMPlacePageEntity * entity = self.manager.entity; entity.bookmarkDescription = self.textView.text; [entity synchronize]; - [self.textView resignFirstResponder]; - - if (entity.isHTMLDescription) - self.state = BookmarkDescriptionStateViewHTML; - else - [self popViewController]; + [self cancelTap]; } - (void)backTap diff --git a/iphone/Maps/Classes/MWMPlacePage.h b/iphone/Maps/Classes/MWMPlacePage.h index 1cecf32f0b..8b257bea09 100644 --- a/iphone/Maps/Classes/MWMPlacePage.h +++ b/iphone/Maps/Classes/MWMPlacePage.h @@ -31,7 +31,7 @@ - (void)route; - (void)reloadBookmark; - (void)apiBack; -- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight; +- (void)willStartEditingBookmarkTitle; - (void)willFinishEditingBookmarkTitle:(NSString *)title; - (void)addPlacePageShadowToView:(UIView *)view offset:(CGSize)offset; @@ -41,6 +41,8 @@ - (void)setDistance:(NSString *)distance; - (void)updateMyPositionStatus:(NSString *)status; +- (void)keyboardWillChangeFrame:(NSNotification *)aNotification; + - (instancetype)init __attribute__((unavailable("call initWithManager: instead"))); @end diff --git a/iphone/Maps/Classes/MWMPlacePage.mm b/iphone/Maps/Classes/MWMPlacePage.mm index 6ce2696f95..bc6de72ac6 100644 --- a/iphone/Maps/Classes/MWMPlacePage.mm +++ b/iphone/Maps/Classes/MWMPlacePage.mm @@ -36,6 +36,15 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; options:NSKeyValueObservingOptionNew context:nullptr]; } + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillChangeFrame:) + name:UIKeyboardWillChangeFrameNotification + object:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(keyboardWillHide) + name:UIKeyboardWillHideNotification + object:nil]; } return self; } @@ -46,6 +55,18 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; { [self.extendedPlacePageView removeObserver:self forKeyPath:kPlacePageViewCenterKeyPath]; } + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +- (void)keyboardWillChangeFrame:(NSNotification *)aNotification +{ + NSDictionary * info = [aNotification userInfo]; + self.keyboardHeight = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height; +} + +- (void)keyboardWillHide +{ + self.keyboardHeight = 0.0; } - (void)observeValueForKeyPath:(NSString *)keyPath @@ -98,7 +119,6 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; { [self.basePlacePageView removeBookmark]; [self.manager removeBookmark]; - self.keyboardHeight = 0.; } - (void)share @@ -165,16 +185,10 @@ static NSString * const kPlacePageViewCenterKeyPath = @"center"; [self.basePlacePageView reloadBookmarkCell]; } -- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight -{ - self.keyboardHeight = keyboardHeight; -} - - (void)willFinishEditingBookmarkTitle:(NSString *)title { self.basePlacePageView.titleLabel.text = title; [self.basePlacePageView layoutIfNeeded]; - self.keyboardHeight = 0.; } - (IBAction)didTap:(UITapGestureRecognizer *)sender diff --git a/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm b/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm index d1da9d8f45..8eb3988319 100644 --- a/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm +++ b/iphone/Maps/Classes/MWMPlacePageBookmarkCell.mm @@ -96,10 +96,8 @@ static NSUInteger sWebViewHeight = 0; - (void)keyboardWillShown:(NSNotification *)aNotification { - NSDictionary const * info = [aNotification userInfo]; - CGSize const kbSize = [info[UIKeyboardFrameEndUserInfoKey] CGRectValue].size; if ([self.title isEditing]) - [self.placePage willStartEditingBookmarkTitle:kbSize.height]; + [self.placePage willStartEditingBookmarkTitle]; } - (void)keyboardWillBeHidden diff --git a/iphone/Maps/Classes/MWMiPadPlacePage.mm b/iphone/Maps/Classes/MWMiPadPlacePage.mm index e5045084f1..70a5082ec4 100644 --- a/iphone/Maps/Classes/MWMiPadPlacePage.mm +++ b/iphone/Maps/Classes/MWMiPadPlacePage.mm @@ -141,9 +141,8 @@ static CGFloat const kKeyboardOffset = 12.; }]; } -- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight +- (void)willStartEditingBookmarkTitle { - [super willStartEditingBookmarkTitle:keyboardHeight]; [self updatePlacePagePosition]; } @@ -191,6 +190,7 @@ static CGFloat const kKeyboardOffset = 12.; MWMBookmarkDescriptionViewController * controller = [[MWMBookmarkDescriptionViewController alloc] initWithPlacePageManager:self.manager]; controller.iPadOwnerNavigationController = self.navigationController; [self.navigationController pushViewController:controller animated:YES]; + [self updatePlacePageLayoutAnimated:NO]; } - (IBAction)didPan:(UIPanGestureRecognizer *)sender @@ -238,8 +238,10 @@ static CGFloat const kKeyboardOffset = 12.; UITableView * featureTable = self.basePlacePageView.featureTable; CGFloat const height = self.navigationController.view.height; CGFloat const tableContentHeight = featureTable.contentSize.height; - CGFloat const headerViewHeight = self.basePlacePageView.separatorView.maxY; - CGFloat const availableTableHeight = height - headerViewHeight - self.actionBar.height; + CGFloat const headerHeight = self.basePlacePageView.separatorView.maxY; + CGFloat const actionBarHeight = self.actionBar.height; + CGFloat const anchorHeight = self.anchorImageView.height; + CGFloat const availableTableHeight = height - headerHeight - actionBarHeight - anchorHeight; CGFloat const externalHeight = tableContentHeight - availableTableHeight; if (externalHeight > 0.) { @@ -248,22 +250,35 @@ static CGFloat const kKeyboardOffset = 12.; } else { - [featureTable setContentOffset:CGPointZero animated:YES]; + featureTable.contentInset = UIEdgeInsetsZero; featureTable.scrollEnabled = NO; } } +- (void)keyboardWillChangeFrame:(NSNotification *)aNotification +{ + [super keyboardWillChangeFrame:aNotification]; + [self updateHeight]; +} + - (CGFloat)getAvailableHeight { CGFloat const bottomOffset = self.keyboardHeight > 0.0 ? kKeyboardOffset : kBottomOffset; - return self.parentViewHeight - self.keyboardHeight - kTopOffset - bottomOffset; + CGFloat const availableHeight = self.parentViewHeight - self.keyboardHeight - kTopOffset - bottomOffset; + return availableHeight; } #pragma mark - Properties - (void)setHeight:(CGFloat)height { - _height = MIN(height, [self getAvailableHeight]); + _height = height; + [self updateHeight]; +} + +- (void)updateHeight +{ + _height = MIN(_height, [self getAvailableHeight]); self.navigationController.view.height = _height; self.extendedPlacePageView.height = _height; } diff --git a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm index 810a24d929..ba44905e56 100644 --- a/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhoneLandscapePlacePage.mm @@ -131,9 +131,8 @@ typedef NS_ENUM(NSUInteger, MWMiPhoneLandscapePlacePageState) } } -- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight +- (void)willStartEditingBookmarkTitle { - [super willStartEditingBookmarkTitle:keyboardHeight]; CGFloat const statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height; MWMBasePlacePageView const * basePlacePageView = self.basePlacePageView; UITableView const * tableView = basePlacePageView.featureTable; diff --git a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm index dd60bed250..0221c0c75c 100644 --- a/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm +++ b/iphone/Maps/Classes/MWMiPhonePortraitPlacePage.mm @@ -220,9 +220,8 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) } } -- (void)willStartEditingBookmarkTitle:(CGFloat)keyboardHeight +- (void)willStartEditingBookmarkTitle { - [super willStartEditingBookmarkTitle:keyboardHeight]; self.state = MWMiPhonePortraitPlacePageStateOpen; } @@ -270,7 +269,6 @@ typedef NS_ENUM(NSUInteger, MWMiPhonePortraitPlacePageState) __strong MWMiPhonePortraitPlacePage * self = weakSelf; if (self.state == MWMiPhonePortraitPlacePageStateClosed) { - self.keyboardHeight = 0.; [self.manager dismissPlacePage]; } else