- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我遇到了 View Controller 包含的问题,我想通过自定义演示/动画“在当前上下文中”呈现 View Controller 。
我有一个 Root View Controller ,它有两个 subview Controller ,它们可以作为根的 subview Controller 添加和删除。当这些 subview Controller 呈现一个 View Controller 时,我希望呈现在当前上下文之上,以便当呈现的 subview 从 View 层次结构中移除并释放时,呈现的模态也将被移除。此外,如果 child A 呈现一个 View Controller ,我希望 child B 的“presentedViewController”属性在“当前上下文”演示中为 nil,即使 A 仍在呈现。
当我将呈现的 View Controller 的 modalPresentationStyle
设置为 overCurrentContext
并且 subview Controller 设置了 definesPresentationContext
时,一切都按预期工作为真。
如果我将 modalPresentationStyle
设置为 custom
并覆盖 shouldPresentInFullscreen
在我的返回 false自定义呈现 Controller 。
这是一个说明问题的例子:
import UIKit
final class ProgressController: UIViewController {
private lazy var activityIndicatorView = UIActivityIndicatorView(activityIndicatorStyle: .white)
private lazy var progressTransitioningDelegate = ProgressTransitioningDelegate()
// MARK: Lifecycle
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
setup()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
override public func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor(white: 0, alpha: 0)
view.addSubview(activityIndicatorView)
activityIndicatorView.startAnimating()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override public func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
activityIndicatorView.center = CGPoint(x: view.bounds.width/2, y: view.bounds.height/2)
}
// MARK: Private
private func setup() {
modalPresentationStyle = .custom
modalTransitionStyle = .crossDissolve
transitioningDelegate = progressTransitioningDelegate
}
}
final class ProgressTransitioningDelegate: NSObject, UIViewControllerTransitioningDelegate {
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return DimBackgroundPresentationController(presentedViewController: presented, presenting: source)
}
}
final class DimBackgroundPresentationController: UIPresentationController {
lazy var overlayView: UIView = {
let v = UIView()
v.backgroundColor = UIColor(white: 0, alpha: 0.5)
return v
}()
override var shouldPresentInFullscreen: Bool {
return false
}
override func presentationTransitionWillBegin() {
super.presentationTransitionWillBegin()
overlayView.alpha = 0
containerView!.addSubview(overlayView)
containerView!.addSubview(presentedView!)
if let coordinator = presentedViewController.transitionCoordinator {
coordinator.animate(alongsideTransition: { _ in
self.overlayView.alpha = 1
}, completion: nil)
}
}
override func containerViewDidLayoutSubviews() {
super.containerViewDidLayoutSubviews()
overlayView.frame = presentingViewController.view.bounds
}
override func dismissalTransitionWillBegin() {
super.dismissalTransitionWillBegin()
let coordinator = presentedViewController.transitionCoordinator
coordinator?.animate(alongsideTransition: { _ in
self.overlayView.alpha = 0
}, completion: nil)
}
}
class ViewControllerA: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
definesPresentationContext = true
let vc = ProgressController()
self.present(vc, animated: true) {
}
}
}
class ViewController: UIViewController {
let container = UIScrollView()
override func viewDidLoad() {
super.viewDidLoad()
container.frame = view.bounds
view.addSubview(container)
let lhs = ViewControllerA()
lhs.view.backgroundColor = .red
let rhs = UIViewController()
rhs.view.backgroundColor = .blue
addChildViewController(lhs)
lhs.view.frame = CGRect(x: 0, y: 0, width: view.bounds.width, height: view.bounds.height)
container.addSubview(lhs.view)
lhs.didMove(toParentViewController: self)
addChildViewController(rhs)
rhs.view.frame = CGRect(x: view.bounds.width, y: 0, width: view.bounds.width, height: view.bounds.height)
container.addSubview(rhs.view)
rhs.didMove(toParentViewController: self)
container.contentSize = CGSize(width: view.bounds.width * 2, height: view.bounds.height)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// let rect = CGRect(x: floor(view.bounds.width/2.0), y: 0, width: view.bounds.width, height: view.bounds.height)
// container.scrollRectToVisible(rect, animated: true)
}
}
如果将 ProgressController
上的 setup()
函数更改为:
private func setup() {
modalPresentationStyle = .overCurrentContext
modalTransitionStyle = .crossDissolve
transitioningDelegate = progressTransitioningDelegate
}
表示/ View 层次结构将按预期运行,但不会使用自定义表示。
Apple 的 shouldPresentInFullscreen
文档似乎表明这应该有效:
The default implementation of this method returns true, indicating that the presentation covers the entire screen. You can override this method and return false to force the presentation to display only in the current context.
If you override this method, do not call super.
我在 iOS 10 上的 Xcode 8 和 iOS 11 上的 Xcode 9 中对此进行了测试,上面的代码在任何一种情况下都无法按预期工作。
最佳答案
我猜你发现了一个错误。文档说 shouldPresentInFullscreen
可以将其转换为 currentContext
演示文稿,但它什么也没做。 (除了你的测试和我的测试外,我还发现了一些网上对此的投诉,导致我认为是这样。)
结论是,如果您使用演示风格,您将无法获得默认的 currentContext
行为(其中运行时查询源 View Controller 并在层次结构中向上查找 definesPresentationContext
) .custom
.
我建议向 Apple 提交错误。
关于ios - 如何使用自定义转换在当前上下文中呈现 View Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45966293/
我试图通过这段代码读取未知数量的整数: while (1) { int c = getchar (); if (c == EOF) break;
我正试图找到一个类似于谷歌分析日期选择器的日期选择器: 知道 jQuery 是否提供了类似的东西吗? 最佳答案 这个 Twitter Bootstrap 风格的日期范围选择器非常接近。 https:/
我正在使用 javascript。如何获取当前 URL 的路径并将其分配给我的代码?这是我的代码: $(document).ready(function() { $(".share").hides
如何获得今天的Julian day number (JDN)相等的?或任何日期? 我看了又看,但只发现了一些产生“year-dayOfYear”的函数,而不是:2457854。 最佳答案 在 bash
我有相当简单的 UDP 服务器写在 c 上。 有时我需要知道在套接字中排队的所有 udp 数据包(字节)的当前长度。 据我了解,getsockopt 没有得到这样的信息。 欢迎使用 Linux 和 F
我一直在寻找几个小时来找到一个可以在图像中添加诸如“填充:5px”之类的东西的插件。每个人都通过纯 html 做到这一点吗?我们的客户需要一种方法来简单地使用按钮或右键单击上下文菜单来添加它。有什么建
是否有可能获得当前正在执行的 TCL 脚本的完整路径? 在 PHP 中,它将是:__FILE__ 最佳答案 根据“当前正在执行的 TCL 脚本”的含义,您实际上可能会寻找 info script ,甚
我最近从直接使用 ISession 转向了包装的 ISession,即工作单元类型模式。 我曾经使用 SQL Lite(内存中)对此进行测试。我有一个简单的帮助器类,它配置我的 SessionFact
我按照步骤操作 here在 WebStorm 中配置代码完成和其他内容,但我仍然收到以下语法错误。 我该如何解决这个问题? 最佳答案 通过相应地将“JavaScript 语言版本”(Settings/
我可以为我团队的 TFS 当前 Sprint 任务板添加书签吗?我们有两周的冲刺,因此 URL 每两周更改一次。 默认 URL 的形式为: http://[Server]/tfs/[Project]/
是否有 Subversion 命令可以显示当前版本号? 在svn checkout之后,我想启动一个脚本并需要变量中的修订号。如果有像 svn info get_revision_number 这样的
我正在编写表单的一个组件 首次安装组件时,sources={{}} ,一本空字典。由于该组件包装了现有的 Javascript 库,因此我正在实现一个自定义比较函数。为了让这个 diffing 函数
无论系统时间设置为多少以及机器所在的时区,我都需要正确的 UTC 时间。 (即使我必须打电话到互联网才能同步......) 是否有一些库或其他方法可以优雅地做到这一点? 最佳答案 如果您想获得准确可靠
我一边编码,一边拿出一些我和 friend 建立的旧网站来重新开始工作。我已经有一段时间没有做过任何 AJAX 了,当我试图找出我的代码失败的地方时,我发现没有显示很多资源。我猜这是因为我使用的是旧方
由于对性能的巨大影响,我从不怀疑我现在的桌面CPU是否有分支预测。当然可以。但各种 ARM 产品又如何呢? iPhone或Android手机有分支预测吗?较旧的任天堂 DS?基于 PowerPC 的
我有一个具有以下有效负载的 JWT: { "id": "394a71988caa6cc30601e43f5b6569d52cd7f6df", "jti": "394a71988caa6cc30
从其他一些帖子中,我能够通过以下方式获取当前 URI: 但是以下方法不起作用: 我很好奇为什么上面的方法不起作用,以及如何将当前 URI 分配给字符串。 最佳答案 每the javadocs ,g
我在表格 View 中有几个单元格。现在在任何给定的时间点,我想计算 View 中单元格的当前高度,即如果它是 View 的 3/4,它应该返回 (cellheight)*3/4 高度。 我通过以下方
这是网站的身份验证脚本。这安全吗?是最近的节目吗?它已经过时了吗?是否有“更好更安全的方法”我很新,但我没有看到太多地方使用 header 授权。 如有任何帮助,我们将不胜感激!这是我制作的第一个登录
我已经在其他 stackoverflow 线程上检查过这个错误,但在我的代码中没有发现任何错误。也许我累了,但我觉得还好。 网站.urls.py: from django.conf.urls impo
我是一名优秀的程序员,十分优秀!