如何在ipad的UiSplitviewcontroller中隐藏主视图
是否有任何方法可以通过编程方式隐藏splitviewcontroller中的主视图。在我的应用程序中,第一个屏幕是splitviewcontroller,下一个屏幕不需要任何分割视图。如何实现这一点虽然没有很好的过渡(抱歉),但可以通过将根视图设置为局部视图控制器的视图,然后与UISplitView交换视图,并将局部视图移动到UISplitView来实现。(实际上,您可能可以设置视图交换(推/翻转/等)的动画,但在视图更改动画期间更改任何内容都不是一个好主意,将细节视图移动到UISplitView内部可能符合条件。)不知道这是否是您要查找的内容。例如,要在单击按钮时在横向模式下隐藏主视图,可以执行以下操作(在选择器方法中) 试试这个:如何在ipad的UiSplitviewcontroller中隐藏主视图,ipad,uisplitviewcontroller,Ipad,Uisplitviewcontroller,是否有任何方法可以通过编程方式隐藏splitviewcontroller中的主视图。在我的应用程序中,第一个屏幕是splitviewcontroller,下一个屏幕不需要任何分割视图。如何实现这一点虽然没有很好的过渡(抱歉),但可以通过将根视图设置为局部视图控制器的视图,然后与UISplitView交换视图,并将局部视图移动到UISplitView来实现。(实际上,您可能可以设置视图交换(推/翻转/等)的动画,但在视图更改动画期间更改任何内容都不是一个好主意,将细节视图移动到UISplitVie
splitVC.modalPresentationStyle=UIModalPresentationFullScreen;
[splitVC presentModalViewController:[[splitVC ViewController]对象索引:1]动画:否];
为我在4.2上工作
下面是另一个非常棒的技巧。在SDK 5.0中,他们为UISPlitViewController添加了新方法,可以轻松地完成这项工作。只需像“下一步”一样实现它,您将不会看到主视图:
- (BOOL)splitViewController:(UISplitViewController*)svc
shouldHideViewController:(UIViewController *)vc
inOrientation:(UIInterfaceOrientation)orientation
{
return YES;
}
唯一可以看到的地方是旋转-主视图的部分在动画期间可见。我已经用一种简单的方法修复了这个问题,只是在master中加载了空视图和黑色视图
PS:不确定这是否适用于i0707。但希望这对现在有同样问题的其他人有用。这是有效的:
将“隐藏”方法附加到按钮,例如:
UIBarButtonItem *hideButton = [[UIBarButtonItem alloc] initWithTitle:@"hide"
style: UIBarButtonItemStylePlain
target: self
action: @selector(hide:)
];
[self.mainView.navigationItem setLeftBarButtonItem:hideButton];
在这段代码中,“self.mainView”是splitview第二个视图中导航控制器中的视图控制器,只是作为参考
hide方法看起来是这样的
-(void)hide:(id)sender
{
UIViewController *masterController = [self.viewControllers objectAtIndex:0];
CGRect selfFrame = self.view.frame;
CGFloat aWidth = masterController.view.frame.size.width;
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.30f];
if(orientation == UIDeviceOrientationLandscapeLeft)
{
selfFrame.size.height += aWidth;
selfFrame.origin.y -= aWidth;
}
else if(orientation == UIDeviceOrientationLandscapeRight)
{
selfFrame.size.height += aWidth;
}
[self.view setFrame:selfFrame];
[UIView commitAnimations];
}
这是起点,显然需要做更多的逻辑来处理旋转,再次显示它,等等
我希望这有帮助
通过iOS5和Xcode 4.3测试,Matt Gemmell创建了一个名为“MGSplitViewController”的优秀自定义splitViewController。它非常容易实现,有大量注释,并且包含许多普通splitViewController所没有的优秀功能(在横向视图中隐藏主视图,在横向视图中更改拆分的位置,允许用户在运行时流畅地更改拆分的大小等) 信息和演示:
直接到源代码:但是,当我尝试时,上面的代码对我不起作用
CGRect selfFrame=self.splitViewController.view.frame;
是的。所以…这对我来说很有用。。(此代码应位于detailviewcontroller中)
-(无效)隐藏主控器{
UIViewController*masterController=GetAppDelegate().masterController;
CGRect selfFrame=self.splitViewController.view.frame;
CGFloat aWidth=主控制器.view.frame.size.width;
UIDeviceOrientation方向=[[UIDevice currentDevice]方向];
[UIView beginAnimations:nil上下文:NULL];
[UIView设置动画持续时间:0.30f];
if(方向==UIDeviceOrientationAndscapeLeft)
{
selfFrame.size.height+=aWidth;
selfFrame.origin.y-=aWidth;
}
else if(方向==UIDeviceOrientationAndscapeRight)
{
selfFrame.size.height+=aWidth;
}
[self.splitViewController.view setFrame:selfFrame];
[UIView委员会];
}
为了允许旋转,需要:
-(void)WillAnimateRotationInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation持续时间:(NSTimeInterval)持续时间
{
[super-WillAnimateRotationInterfaceOrientation:interfaceOrientation持续时间:duration];//不确定是否需要
//调用此方法时,视图的边界已更改
[UIView beginAnimations:nil上下文:NULL];
[UIView setAnimationBeginsFromCurrentState:是];
if(UIInterfaceOrientationSportRait(interfaceOrientation)){
如果(Masterisheden){
[自我展示大师];
}
}否则{
如果(自编辑){
[自我隐藏者];
}
}
[UIView setAnimationDuration:duration];
[UIView委员会];
}
SplitViewController提供的BarButtonim是以编程方式隐藏主视图控制器的关键
这个密码很危险!但优雅:)
导入目标c消息库
#导入
接下来,获取SplitViewController提供的UIBarButtonItem的句柄
-(void)splitViewController:(UISplitViewController*)splitController将隐藏设备控制器:(UIViewController*)带有barButtonItem的viewController:(UIBarButtonItem*)barButtonItem
用于popoverController:(UIPopoverController*)popoverController
{
barButtonItem.title=@“主人”;
[self.navigationItem setLeftBarButtonItem:barButtonItem动画:是];
//获得巴布托人的把柄
[自设置主按钮项:巴布通项];
}
然后,当触发事件时,应触发主视图控制器的自动解除,即
-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indepath
你可以这样做
objc\u msgSend(self.masterButtonItem.target,self.masterButtonItem.action);
与杰克的答案相同,但只有一行。进入-(void)setDetailItem:(id)newDetailItem{…}以解除主机
[[UIApplication sharedApplication] sendAction: self.navigationItem.leftBarButtonItem.action
to: self.navigationItem.leftBarButtonItem.target
from: nil
forEvent: nil];
当你说隐藏主视图时,你的意思是在SplitViewController的左侧创建一个空白视图,还是让DetailViewController在横向模式下填满100%的屏幕?第二个选项,让DetailViewController在任一模式(横向或纵向)下填满100%的屏幕。有解决方案吗?我也试着做同样的事,我也试过了
[[UIApplication sharedApplication] sendAction: self.navigationItem.leftBarButtonItem.action
to: self.navigationItem.leftBarButtonItem.target
from: nil
forEvent: nil];