ios - 如何将 UIViewController 呈现为局部 View ?
<p><p>例如,音乐应用程序的“正在播放”屏幕和邮件应用程序的电子邮件撰写屏幕,如下所示:</p>
<p> <a href="/image/FTLNb.jpg" rel="noreferrer noopener nofollow"><img src="/image/FTLNbm.jpg" alt="modal example screenshot"/></a> <a href="/image/1GHWJ.jpg" rel="noreferrer noopener nofollow"><img src="/image/1GHWJm.jpg" alt="modal example screenshot"/></a> </p>
<p>我该如何表达我的观点?我假设它不能仅使用 Storyboard来实现,因为所有选项似乎都覆盖了全屏,而不是所需的部分模态。 </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>这不是最近的问题,所以我把它留待以后使用。希望您已经做到了。</p>
<p>首先您需要做的就是关注<a href="https://www.raywenderlich.com/139277/uipresentationcontroller-tutorial-getting-started" rel="noreferrer noopener nofollow">this UIPresentationController guide</a>原样。</p>
<p>然后将<em>呈现</em>ViewController 框架调整到大于屏幕的 2/3。</p>
<pre><code>override func containerViewWillLayoutSubviews() {
presentedView?.frame = frameOfPresentedViewInContainerView
presentedView?.layer.cornerRadius = 5.0
presentedView?.layer.masksToBounds = true
}
override func size(forChildContentContainer container: UIContentContainer,
withParentContainerSize parentSize: CGSize) -> CGSize {
switch direction {
case .left, .right:
return CGSize(width: parentSize.width*(2.0/3.0), height: parentSize.height)
case .bottom, .top:
return CGSize(width: parentSize.width, height: parentSize.height-40.0)
}
}
override var frameOfPresentedViewInContainerView: CGRect {
var frame: CGRect = .zero
frame.size = size(forChildContentContainer: presentedViewController,
withParentContainerSize: containerView!.bounds.size)
switch direction {
case .right:
frame.origin.x = containerView!.frame.width*(1.0/3.0)
case .bottom:
frame.origin.y = 40.0
default:
frame.origin = .zero
}
return frame
}
</code></pre>
<p>然后在调光动画期间设置<em>呈现</em> ViewController 框架。</p>
<pre><code> self.presentingFrame = self.presentingViewController.view.frame
var frame = self.presentingFrame
frame.size.width -= 40.0
frame.size.height -= 60.0
frame.origin.x += 20.0
frame.origin.y += 30.0
coordinator.animate(alongsideTransition: { _ in
self.dimmingView.alpha = 1.0
self.presentingViewController.view.frame = frame
self.presentingViewController.view.layer.cornerRadius = 5.0
self.presentingViewController.view.layer.masksToBounds = true
UIApplication.shared.statusBarStyle = .lightContent
})
</code></pre>
<p>别忘了添加反向动画。结果:</p>
<p> <a href="/image/16YvW.png" rel="noreferrer noopener nofollow"><img src="/image/16YvW.png" alt="result!"/></a> </p></p>
<p style="font-size: 20px;">关于ios - 如何将 UIViewController 呈现为局部 View ?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42567440/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42567440/
</a>
</p>
页:
[1]