作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 UIKit 中,我使用下面的代码来呈现具有演示风格的模态视图 Controller 交叉溶解
controller.modalTransitionStyle = .crossDissolve
controller.modalPresentationStyle = .overFullScreen
UIApplication.topViewController()?.present(controller, animated: true, completion: nil)
最佳答案
您可以像这样在 UIViewController 上进行扩展:
struct ViewControllerHolder {
weak var value: UIViewController?
}
struct ViewControllerKey: EnvironmentKey {
static var defaultValue: ViewControllerHolder {
return ViewControllerHolder(value: UIApplication.shared.windows.first?.rootViewController)
}
}
extension EnvironmentValues {
var viewController: UIViewController? {
get { return self[ViewControllerKey.self].value }
set { self[ViewControllerKey.self].value = newValue }
}
}
extension UIViewController {
func present<Content: View>(style: UIModalPresentationStyle = .automatic, transitionStyle: UIModalTransitionStyle = .coverVertical, @ViewBuilder builder: () -> Content) {
let toPresent = UIHostingController(rootView: AnyView(EmptyView()))
toPresent.modalPresentationStyle = style
toPresent.modalTransitionStyle = transitionStyle
toPresent.rootView = AnyView(
builder()
.environment(\.viewController, toPresent)
)
self.present(toPresent, animated: true, completion: nil)
}
}
struct ContentView: View {
@Environment(\.viewController) private var viewControllerHolder: UIViewController?
private var viewController: UIViewController? {
self.viewControllerHolder
}
var body: some View {
Button(action: {
self.viewController?.present(style: .fullScreen, transitionStyle: .coverVertical) {
Text("OK")
}
}) {
Text("Present me!")
}
}
}
关于ios - 如何在 swiftUI 中呈现 crossDissolve View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60391281/
我正在尝试在 UITabBarController 上创建一个过渡效果,有点类似于 Facebook 应用程序。我设法在选项卡开关上获得了“滚动效果”,但我似乎无法弄清楚如何交叉溶解(或者它至少不起作
我展示了一个模态视图 Controller ,它的背景是 UIVisualEffectView 和 .light 类型的 UIBlurEffect 我将展示模态视图 Controller 如下: in
在 UIKit 中,我使用下面的代码来呈现具有演示风格的模态视图 Controller 交叉溶解 controller.modalTransitionStyle = .crossDissolve co
当使用路由在 Flutter 中的两个页面之间导航时,如何从 iOS 重新创建 modalTransitionStyle = .crossDissolve。 最佳答案 在这里,您可以更改 transi
我正在尝试获得熟悉的“半透明叠加”效果。我正在使用 .OverCurrentContext 演示风格,并且所呈现的 VC 具有 0.5 alpha 的 View ,在 Storyboard 中设置。
我是一名优秀的程序员,十分优秀!