From c1b1cda1a440ab2becf2ecc42f7b5f3698f44e1c Mon Sep 17 00:00:00 2001 From: life Date: Fri, 6 Nov 2015 09:55:57 +0800 Subject: [PATCH] =?UTF-8?q?=20=20Edit=20New=20issue=20iPad=20=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A0=B7=E5=BC=8F=E4=BC=98=E5=8C=96,=20=E4=B8=8D?= =?UTF-8?q?=E9=9A=90=E8=97=8FNavigation=20#20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Leanote/controller/BaseViewController.m | 2 +- Leanote/controller/note/NoteController.m | 43 ++++++-- .../controller/notebook/NotebookController.m | 101 ++++++++++++------ Leanote/controller/tag/TagController.m | 97 +++++++++++------ .../en.lproj/MainStoryboard_iPhone.storyboard | 2 +- Leanote/view/LeaSearchDisplayController.m | 2 + 6 files changed, 174 insertions(+), 73 deletions(-) diff --git a/Leanote/controller/BaseViewController.m b/Leanote/controller/BaseViewController.m index c7dcc7a..922ddce 100644 --- a/Leanote/controller/BaseViewController.m +++ b/Leanote/controller/BaseViewController.m @@ -108,7 +108,7 @@ NSString const *key = @"isSelectOnSearchKey"; -(void)setBarStyle { - if(self.isSelectOnSearch) { + if(self.isSelectOnSearch && !IS_IPAD) { [self setBarStyleBlack]; } else { diff --git a/Leanote/controller/note/NoteController.m b/Leanote/controller/note/NoteController.m index e14fd9a..f06ad1c 100755 --- a/Leanote/controller/note/NoteController.m +++ b/Leanote/controller/note/NoteController.m @@ -846,13 +846,38 @@ return titleLen; } -// 搜索 +// ipad下search bar上移, 但navigation却不隐藏 +// ipad下模拟没有navigationController, 但是SWTableViewCell selectCell 要用到 +// http://stackoverflow.com/a/5860412/4269908 +//- (UINavigationController *)navigationController { +// if (IS_IPAD) { +// return nil; +// } else { +// return self.navigationController; +// } +//} +- (UINavigationController *)navigationController { + if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1]; + // Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 + NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"]; + NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]]; + [array removeObject:@""]; + + // Array[3] == class caller + if([array[3] isEqualToString:@"UISearchDisplayController"]) { + return nil; + } + } + return [super navigationController]; +} +// 搜索 #pragma mark - UISearchDisplayDelegate Methods - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { - NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); +// NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); NSString *searchPredicate = [NSString stringWithFormat:@"title contains[cd] '%@' or content contains[cd] '%@'", searchString, searchString]; @@ -868,8 +893,10 @@ - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { - [self setBarStyleBlack]; - self.isSelectOnSearch = YES; + if (!IS_IPAD) { + [self setBarStyleBlack]; + self.isSelectOnSearch = YES; + } } - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller @@ -881,9 +908,11 @@ // 为什么要reload ? // [self.tableView reloadData]; - - [self restoreBarStyle]; - self.isSelectOnSearch = NO; + if (!IS_IPAD) { + [self restoreBarStyle]; + + self.isSelectOnSearch = NO; + } } #pragma mark - UISearchBarDelegate Methods diff --git a/Leanote/controller/notebook/NotebookController.m b/Leanote/controller/notebook/NotebookController.m index b34f38d..86a48c8 100755 --- a/Leanote/controller/notebook/NotebookController.m +++ b/Leanote/controller/notebook/NotebookController.m @@ -124,7 +124,7 @@ self.title = NSLocalizedString(@"Notebook", nil); - // 我靠, 我不是故意的, 如果不加这两名, search bar动画会有突现, 突下的动画 + // 我靠, 我不是故意的, 如果不加这两句, search bar动画会有突现, 突下的动画 // http://stackoverflow.com/a/20975075/4269908 [self setAutomaticallyAdjustsScrollViewInsets:YES]; [self setExtendedLayoutIncludesOpaqueBars:YES]; @@ -139,7 +139,8 @@ { [super viewWillAppear:animated]; - if(self.isSelectOnSearch) { + // 非IPAD下, 如果当前是isSelectOnSearch才要隐藏 + if(self.isSelectOnSearch && !IS_IPAD) { NSLog(@"self.isSelectOnSearch viewWillAppear"); [self.navigationController setNavigationBarHidden:YES animated:animated]; } @@ -791,6 +792,32 @@ return titleLen; } +// ipad下search bar上移, 但navigation却不隐藏 +// ipad下模拟没有navigationController, 但是SWTableViewCell selectCell 要用到 +// http://stackoverflow.com/a/5860412/4269908 +//- (UINavigationController *)navigationController { +// if (IS_IPAD) { +// return nil; +// } else { +// return self.navigationController; +// } +//} +- (UINavigationController *)navigationController { + if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1]; + // Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 + NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"]; + NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]]; + [array removeObject:@""]; + + // Array[3] == class caller + if([array[3] isEqualToString:@"UISearchDisplayController"]) { + return nil; + } + } + return [super navigationController]; +} + #pragma mark - UISearchDisplayDelegate Methods - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView @@ -812,26 +839,30 @@ // 开始搜索, 从点击uisearchbar开始 - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { - [self setBarStyleBlack]; - - // cate - if(self.delegate) { - // 1. 这里控制动画 + if (!IS_IPAD) { - [UIView animateWithDuration:0.25f animations:^{ + [self setBarStyleBlack]; + + // cate + if(self.delegate) { + // 1. 这里控制动画 + + [UIView animateWithDuration:0.25f animations:^{ + CGRect frame = self.view.frame; + frame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height; + self.view.frame = frame; + }]; + NSLog(@"setNavigationBarHidden YES!!!!!!!!!"); + [self.navigationController setNavigationBarHidden:YES animated:YES]; + CGRect frame = self.view.frame; - frame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height; + frame.size.height = [self.delegate getSearchedViewHeight]; self.view.frame = frame; - }]; - NSLog(@"setNavigationBarHidden YES!!!!!!!!!"); - [self.navigationController setNavigationBarHidden:YES animated:YES]; + } - CGRect frame = self.view.frame; - frame.size.height = [self.delegate getSearchedViewHeight]; - self.view.frame = frame; - } + self.isSelectOnSearch = YES; - self.isSelectOnSearch = YES; + } } // 结束搜索, 点击取消 - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller @@ -840,30 +871,34 @@ self.searchedResultsController = nil; // 重新载入数据 -// [controller.searchResultsTableView reloadData]; // 不能有这个, 这个没用!! 有这个会导致选择笔记有问题 + // [controller.searchResultsTableView reloadData]; // 不能有这个, 这个没用!! 有这个会导致选择笔记有问题 [self.tableView reloadData]; - [self restoreBarStyle]; + if (IS_IPAD) { - // cate - if(self.delegate) { - // 2. 还原 + [self restoreBarStyle]; - [UIView animateWithDuration:0.25f animations:^{ - CGRect frame = self.view.frame; - frame.origin.y = 64; - self.view.frame = frame; - } completion:^(BOOL finished) { - if(finished) { + // cate + if(self.delegate) { + // 2. 还原 + + [UIView animateWithDuration:0.25f animations:^{ CGRect frame = self.view.frame; - frame.size.height = [self.delegate getCancelSearchViewHeight]; + frame.origin.y = 64; self.view.frame = frame; - } - }]; + } completion:^(BOOL finished) { + if(finished) { + CGRect frame = self.view.frame; + frame.size.height = [self.delegate getCancelSearchViewHeight]; + self.view.frame = frame; + } + }]; + + [self.navigationController setNavigationBarHidden:NO animated:YES]; + } + self.isSelectOnSearch = NO; - [self.navigationController setNavigationBarHidden:NO animated:YES]; } - self.isSelectOnSearch = NO; } #pragma mark - UISearchBarDelegate Methods diff --git a/Leanote/controller/tag/TagController.m b/Leanote/controller/tag/TagController.m index e0cefde..f8eaceb 100755 --- a/Leanote/controller/tag/TagController.m +++ b/Leanote/controller/tag/TagController.m @@ -127,7 +127,8 @@ [self beautifySearchBar]; [self setBarStyle]; - if(self.isSelectOnSearch) { + // 非IPAD下, 如果当前是isSelectOnSearch才要隐藏 + if(self.isSelectOnSearch && !IS_IPAD) { NSLog(@"self.isSelectOnSearch viewWillAppear"); [self.navigationController setNavigationBarHidden:YES animated:animated]; } @@ -671,6 +672,32 @@ return titleLen; } +// ipad下search bar上移, 但navigation却不隐藏 +// ipad下模拟没有navigationController, 但是SWTableViewCell selectCell 要用到 +// http://stackoverflow.com/a/5860412/4269908 +//- (UINavigationController *)navigationController { +// if (IS_IPAD) { +// return nil; +// } else { +// return self.navigationController; +// } +//} +- (UINavigationController *)navigationController { + if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + NSString *sourceString = [[NSThread callStackSymbols] objectAtIndex:1]; + // Example: 1 UIKit 0x00540c89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163 + NSCharacterSet *separatorSet = [NSCharacterSet characterSetWithCharactersInString:@" -[]+?.,"]; + NSMutableArray *array = [NSMutableArray arrayWithArray:[sourceString componentsSeparatedByCharactersInSet:separatorSet]]; + [array removeObject:@""]; + + // Array[3] == class caller + if([array[3] isEqualToString:@"UISearchDisplayController"]) { + return nil; + } + } + return [super navigationController]; +} + #pragma mark - UISearchDisplayDelegate Methods - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString @@ -687,56 +714,64 @@ - (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { - [self setBarStyleBlack]; - // cate - if(self.delegate) { - // 1. 这里控制动画 + if (!IS_IPAD) { - [UIView animateWithDuration:0.25f animations:^{ + [self setBarStyleBlack]; + // cate + if(self.delegate) { + // 1. 这里控制动画 + + [UIView animateWithDuration:0.25f animations:^{ + CGRect frame = self.view.frame; + frame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height; + self.view.frame = frame; + }]; + + [self.navigationController setNavigationBarHidden:YES animated:YES]; + CGRect frame = self.view.frame; - frame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height; + frame.size.height = [self.delegate getSearchedViewHeight]; self.view.frame = frame; - }]; + } + self.isSelectOnSearch = YES; - [self.navigationController setNavigationBarHidden:YES animated:YES]; - - CGRect frame = self.view.frame; - frame.size.height = [self.delegate getSearchedViewHeight]; - self.view.frame = frame; } - self.isSelectOnSearch = YES; } - (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller { - NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); +// NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd)); self.searchedResultsController.delegate = nil; self.searchedResultsController = nil; [controller.searchResultsTableView reloadData]; [self.tableView reloadData]; - [self restoreBarStyle]; - - // cate - if(self.delegate) { - // 2. 还原 + if (!IS_IPAD) { - [UIView animateWithDuration:0.25f animations:^{ - CGRect frame = self.view.frame; - frame.origin.y = 64; - self.view.frame = frame; - } completion:^(BOOL finished) { - if(finished) { + [self restoreBarStyle]; + + // cate + if(self.delegate) { + // 2. 还原 + + [UIView animateWithDuration:0.25f animations:^{ CGRect frame = self.view.frame; - frame.size.height = [self.delegate getCancelSearchViewHeight]; + frame.origin.y = 64; self.view.frame = frame; - } - }]; + } completion:^(BOOL finished) { + if(finished) { + CGRect frame = self.view.frame; + frame.size.height = [self.delegate getCancelSearchViewHeight]; + self.view.frame = frame; + } + }]; + + [self.navigationController setNavigationBarHidden:NO animated:YES]; + } + self.isSelectOnSearch = NO; - [self.navigationController setNavigationBarHidden:NO animated:YES]; } - self.isSelectOnSearch = NO; } #pragma mark - UISearchBarDelegate Methods diff --git a/Leanote/en.lproj/MainStoryboard_iPhone.storyboard b/Leanote/en.lproj/MainStoryboard_iPhone.storyboard index c49737b..e0f0569 100755 --- a/Leanote/en.lproj/MainStoryboard_iPhone.storyboard +++ b/Leanote/en.lproj/MainStoryboard_iPhone.storyboard @@ -194,7 +194,7 @@ - + diff --git a/Leanote/view/LeaSearchDisplayController.m b/Leanote/view/LeaSearchDisplayController.m index 64d0ca6..7ef90f9 100644 --- a/Leanote/view/LeaSearchDisplayController.m +++ b/Leanote/view/LeaSearchDisplayController.m @@ -14,6 +14,8 @@ { [super setActive: visible animated: animated]; +// [self.searchContentsController.navigationController setNavigationBarHidden: NO animated: NO]; + /* [self.searchContentsController.navigationController setNavigationBarHidden: NO animated: NO];