use*_*195 21 iphone customization ipad uisplitviewcontroller ios5
我在XCode 4.2中创建了一个新的基于拆分视图的项目
然后在DetailViewController.m文件中我添加了这个方法
- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
//This method is only available in iOS5
return NO;
}
Run Code Online (Sandbox Code Playgroud)
现在通过这样做,我可以一次显示我的splitview控制器的左右两部分.
现在我已经UIBarButtonItem在我的DetailViewController导航栏中添加了一个,我希望通过使用它可以在Portrairt和Landscape模式中隐藏和显示我的主视图.
- (IBAction)hideUnhide:(id)sender
{
//How can hide & unhide
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
instead spv.delegate=nil; spv.delegate=self;
Run Code Online (Sandbox Code Playgroud)
你需要做下一个:
[spv willRotateToInterfaceOrientation:self.interfaceOrientation duration:0];
Run Code Online (Sandbox Code Playgroud)
'setNeedsLayout'使UISplitViewController要求"shouldHideViewController"
- (IBAction)hideUnhide:(id)sender {
UISplitViewController* spv = ...;
self.hideMaster= !self.hideMaster;
[ spv.view setNeedsLayout ]
}
Run Code Online (Sandbox Code Playgroud)
在iOS 5.1中,您必须这样做:
内 DetailViewController.m
- (IBAction)hideUnhide:(id)sender {
UISplitViewController* spv = ...;
self.hideMaster= !self.hideMaster;
[spv.view setNeedsLayout];
spv.delegate = nil;
spv.delegate = self;
}
- (BOOL)splitViewController:(UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation {
return self.hideMaster;
}
Run Code Online (Sandbox Code Playgroud)
好吧,你的问题最简单的部分是使用 bool,比如属性 hideMaster,然后
- (IBAction)hideUnhide:(id)sender
{
self.hideMaster= !self.hideMaster;
}
Run Code Online (Sandbox Code Playgroud)
进而...
- (BOOL)splitViewController: (UISplitViewController*)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
//This method is only available in iOS5
return self.hideMaster;
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,但 shouldHideViewController 仅在 splitVC 重绘期间(例如在旋转期间)被调用,因此 master 仅隐藏/取消隐藏。
| 归档时间: |
|
| 查看次数: |
33090 次 |
| 最近记录: |