UIPopoverController的使用
1、初始化UIPopoverController
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
//必须是个 ViewController
/*且该 ViewController的 viewDidLoad方法中要设置其在popover中的尺寸,如
self.contentSizeForViewInPopover = CGSizeMake(300.0, 280.0);
*/
self.recentSearchesPopoverController = popover;
recentSearchesPopoverController.delegate = self; //self要实现UIPopoverControllerDelegate协议
2、设置当popover弹出时,用户仍可以交互的视图
// Ensure the popover is not dismissed if the user taps in the search bar.
popover.passthroughViews = [NSArray arrayWithObject:searchBar];
3、展现popover
[self.recentSearchesPopoverController presentPopoverFromRect:self.searchBar.bounds
inView:self.searchBar
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:NO];
4、消失popover
//dismiss the popover.
[recentSearchesPopoverController dismissPopoverAnimated:YES];
5、实现 UIPopoverControllerDelegate协议的方法
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
}
胖叔——zhulin1987.com