Emp*_*ump 17 cocoa-touch objective-c uinavigationbar modalviewcontroller ios
我有一个带导航栏的导航应用程序,但有一些实例,而不是将视图控制器推入堆栈,我需要以模态方式呈现视图控制器.问题是,当我关闭模态视图控制器时,除了导航栏被隐藏并且(父视图)已经调整大小之外,一切都按预期运行,这是根据文档的预期行为.所以我想我可以简单地调用内置方法取消隐藏导航栏.我已经尝试过了
[self.navigationController setNavigationBarHidden:NO];
Run Code Online (Sandbox Code Playgroud)
以及没有成功的动画版本.
文档在方法中讨论了这一点
presentModalViewController: animated:
Run Code Online (Sandbox Code Playgroud)
在讨论部分,它说,
在iPhone和iPod touch设备上,modalViewController的视图始终全屏显示"和"将modalViewController属性设置为指定的视图控制器.调整其视图大小并将其附加到视图层次结构."然而,文档并没有让我知道在解除模态视图后如何撤消此过程.
有没有其他人经历过这个并找到了解决方案?
编辑:我遇到了同样的问题,所以我没有问自己的问题,而是赞助了这个问题.这是我的具体情况:
在我的例子中,我通过导航控制器在模态视图控制器中呈现图像选择器:
-(void) chooseImage {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
imagepicker = [[UIImagePickerController alloc] init];
imagepicker.allowsEditing = NO;
imagepicker.delegate = self;
imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagepicker.navigationBar.opaque = true;
imagepicker.wantsFullScreenLayout = NO;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if (self.view.window != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagepicker];
[popoverController presentPopoverFromBarButtonItem:reset permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
} else {}
} else {
[self.navigationController presentModalViewController:imagepicker animated:YES];
}
}
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.popoverController dismissPopoverAnimated:true];
} else {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
//Save the image
}
-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[self.popoverController dismissPopoverAnimated:true];
} else {
[self.navigationController dismissModalViewControllerAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
Mic*_*ick 18
确保你从UINavigationController中呈现并解除modalViewController,如下所示:
// show
[self.navigationController presentModalViewController:vc animated:YES];
// dismiss
[self.navigationController dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
如果您的视图控制器实际上在UINavigationController的堆栈上,那么这是处理模式视图控制器的显示和解除的正确方法.如果你的UINavigationBar仍然是隐藏的,那么还有其他一些时髦的东西,我们需要看看你的代码来确定发生了什么.
编辑
我将你的代码复制到我的应用程序中,UIImagePickerController成功呈现并解散,我的UINavigationController的UINavigationBar仍在那里.我真的相信问题出现在你的架构的其他地方.如果您上传带有示例项目的zip,我将会看一看.
小智 11
只需尝试以下代码即可
SettingsViewController *settings = [[SettingsViewController alloc] init];
UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:settings];
[self presentModalViewController:navcont animated:YES];
[settings release];
[navcont release];
Run Code Online (Sandbox Code Playgroud)
需要呈现导航控制器以便在所呈现的控制器上具有导航条
看一下这个。这是 UIViewController Class Reference 下的 Apple 文档:
\n\n它明确提到模态视图始终以全屏模式呈现,因此很明显导航栏将被隐藏。因此,将单独的导航栏放在模态视图上以导航回来。
\n\npresentModalViewController:animated:\nPresents a modal view managed by the given view controller to the user.\n\n- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated\nParameters\nmodalViewController\nThe view controller that manages the modal view.\nanimated\nIf YES, animates the view as it\xe2\x80\x99s presented; otherwise, does not.\nDiscussion\nOn iPhone and iPod touch devices, the view of modalViewController is always presented full screen. On iPad, the presentation depends on the value in the modalPresentationStyle property.\n\nSets the modalViewController property to the specified view controller. Resizes its view and attaches it to the view hierarchy. The view is animated according to the transition style specified in the modalTransitionStyle property of the controller in the modalViewController parameter.\n\nAvailability\nAvailable in iOS 2.0 and later.\n
Run Code Online (Sandbox Code Playgroud)\n\n希望这可以帮助您理解隐藏整个视图以及导航控制器是模态视图的默认行为,因此请尝试在模态视图中放置单独的导航栏进行导航。
\n\n您可以在此链接上进一步检查
\n\n\n 归档时间: |
|
查看次数: |
31449 次 |
最近记录: |