When the UISearchDisplayController and UISearchBar in iOS7 are used together, sometimes the search box gets the focus, and the shaded part blocks the search box, which affects user usage, as shown in figure
{
for(UIView * v in controller.searchResultsTableView.superview.subviews) { NSLog(@"%@",[v class]); if([v isKindOfClass:NSClassFromString(@"_UISearchDisplayControllerDimmingView")]) { v.frame = CGRectMake(0,20,320,400); // } }
}
3. After modifying the code above, the mask layer does not block the search box, but you still find that the focus cannot be obtained in the lower area of the search box, And the Cancel button is not easy to use.
4. You can see from the previous figure that although the mask layer goes down, there is still a layer blocking. In the left list, this layer is displayed as the parent view of searchResultsTableView and the code is modified again.
- ()searchDisplayControllerWillBeginSearch:(UISearchDisplayController *= CGRectMake(,,,(UIView * v ,[v ([v isKindOfClass:NSClassFromString(= CGRectMake(,,,);
5. Solve the Problem and use the search box properly.
) SearchDisplayController :( UISearchDisplayController *) controller didShowSearchResultsTableView :( UITableView * = CGRectMake (, 320,480 --
7. After multiple tests, it is found that the first execution is invalid because searchDisplayControllerWillBeginSearch is null during the first execution and is not added to the parent view. Two solutions can be used.
Solution 1: delayed execution:
- ()searchDisplayControllerWillBeginSearch:(UISearchDisplayController *- (== (offset == =CGRectMake(,,,(UIView * v ,[v ([v isKindOfClass:NSClassFromString(= CGRectMake(,,,);
Solution 2: register the keyboard notification:
- (- (- (== (offset == =CGRectMake(,,,(UIView * v ,[v ([v isKindOfClass:NSClassFromString(= CGRectMake(,,,);
Solve the problem!
Note: The above frame adjustment is executed on ios7 and is not required in versions earlier than ios7.