我正在关注当iPad处于纵向时隐藏分割视图左侧的演示,然后按下放置在工具栏中的按钮时将其显示为弹出窗口。我一步一步地按照所有步骤进行操作(除此之外)当我按下按钮时,而不是在弹出窗口中,视图显示从左向右滑动。我还注意到,我可以通过从左向右滑动手指而不是按下按钮来获得相同的结果。 这是我使用的代码(相同的代码在演示中正常工作)。
应该在Popover中显示的视图的View Controller中的:
-(BOOL)splitViewController:(UISplitViewController*)svc
shouldHideViewController:(UIViewController*)vc
inOrientation:(UIInterfaceOrientation)orientation
{
return [self splitViewBarButtonItemPresenter] ? UIInterfaceOrientationIsPortrait(orientation) : NO;
}
-(void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
{
barButtonItem.title = self.title;
[self splitViewBarButtonItemPresenter].splitViewBarButtonItem = barButtonItem;
}
-(void)splitViewController:(UISplitViewController *)svc
willShowViewController:(UIViewController *)aViewController
invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
[self splitViewBarButtonItemPresenter].splitViewBarButtonItem = nil;
}
在应显示Popover的视图中:
-(void)setSplitViewBarButtonItem:(UIBarButtonItem *)splitViewBarButtonItem
{
if (_splitViewBarButtonItem != splitViewBarButtonItem){
NSMutableArray *toolbarItems = [self.toolbar.items mutableCopy];
if (_splitViewBarButtonItem) [toolbarItems removeObject:_splitViewBarButtonItem];
if (splitViewBarButtonItem) [toolbarItems insertObject:splitViewBarButtonItem atIndex:0];
self.toolbar.items = toolbarItems;
_splitViewBarButtonItem = splitViewBarButtonItem;
}
}
SplitViewBarButtonItemPresenter
只是一个协议,用于委托谁应该显示(你猜对了!)弹出框的按钮。