obsidian/笔记文件/2.笔记/presentFromViewController.md

31 lines
2.0 KiB
Markdown
Raw Permalink Normal View History

2025-03-26 00:02:56 +08:00
#ios
`presentFromViewController` 并不是 iOS 开发中的一个标准方法名,但你可能是在谈论在 iOS 中使用模态视图控制器modal view controller的呈现方式。在 iOS 中,通常使用 `presentViewController:animated:completion:` 方法(或者在 Swift 中使用 `present(_:animated:completion:)`)来从一个视图控制器模态地呈现另一个视图控制器。
这里有一个基本的例子,展示了如何从一个视图控制器模态地呈现另一个视图控制器:
``` objc
// Objective-C 代码
UIViewController *modalViewController = [[UIViewController alloc] init];
// 对 modalViewController 进行配置,比如设置它的视图等
[self presentViewController:modalViewController animated:YES completion:nil];
```
在 Swift 中,这将是:
``` swift
// Swift 代码
let modalViewController = UIViewController()
// 对 modalViewController 进行配置,比如设置它的视图等
self.present(modalViewController, animated: true, completion: nil)
```
在这个例子中,`self` 是当前正在显示视图控制器的实例,而 `modalViewController` 是你想要模态呈现的视图控制器。`animated:` 参数指定呈现时是否要有动画效果,而 `completion:` 参数是一个可选的闭包,它在呈现动画完成后执行。
如果你是在寻找一个特定的方法或属性名为 `presentFromViewController`,那么可能是你看到的代码或者库中对标准方法的封装或者扩展。在那种情况下,你需要查看那个特定库或代码片段的文档来了解它的用法和实现。
另外如果你是在谈论自定义转场custom transition或者想要在呈现模态视图控制器时有更多的控制你可能需要查看 `UIViewControllerTransitioningDelegate` 协议和相关的 API它们允许你自定义视图控制器之间的转场动画。
在[[SurveyMonkey SDK]]这个第三方SDK 中,也是使用这种方式,实现视图控制器的切换和跳转
![[Pasted image 20241025095906.png]]