- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图使用 Swift 协议(protocol)提供 UIViewControllerAnimatedTransitioning
的通用实现,但每当我有一个符合该协议(protocol)的对象时,我都会收到错误:
Command failed due to signal: Segmentation fault: 11
当删除泛型时,我仍然遇到问题。
这是我的协议(protocol),其中泛型被注释掉:
protocol TransitionControllerType: UIViewControllerAnimatedTransitioning {
// typealias PresentingViewController: UIViewController
// typealias PresentedViewController: UIViewController
var isPresentation: Bool { get set }
var presentationTransitionDuration: NSTimeInterval { get }
var dismissTransitionDuration: NSTimeInterval { get }
func prepareViewControllerForPresentation(viewController: UIViewController, presentingViewController: UIViewController)
func presentViewController(viewController: UIViewController, presentingViewController: UIViewController)
func dismissViewController(viewController: UIViewController, presentingViewController: UIViewController)
}
PresentingViewController
和 PresentedViewController
只是代替 prepareViewController(::)
中的 UIViewController
,presentViewController(::)
和 dismissViewController(::)
。
我在 TransitionControllerType
的扩展中提供了 UIViewControllerAnimatedTransitioning
的实现:
extension TransitionControllerType {
func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
return isPresentation ? presentationTransitionDuration : dismissTransitionDuration
}
func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
// Ensure there is a container view
guard let containerView = transitionContext.containerView() else {
return
}
// Get the view controllers
let (fromViewController, toViewController) = transitionContext.viewControllers()
// // Cast the view controllers
// guard let presentedViewController = (isPresentation ? toViewController : fromViewController) as? PresentedViewController,
// let presentingViewController = (isPresentation ? fromViewController : toViewController) as? PresentingViewController
// else {
// return
// }
guard let presentedViewController = (isPresentation ? toViewController : fromViewController),
let presentingViewController = (isPresentation ? fromViewController : toViewController)
else {
return
}
// Get the views from the view controllers
let presentedView = presentedViewController.view
let presentingView = presentingViewController.view
// If it's a presentation, prepare the view controllers
if isPresentation {
prepareViewControllerForPresentation(presentedViewController, presentingViewController: presentingViewController)
containerView.addSubview(presentedView)
}
UIView.animateWithDuration(
transitionDuration(transitionContext),
delay: 0,
usingSpringWithDamping: isPresentation ? PresentationSpringDamping : DismissSpringDamping,
initialSpringVelocity: isPresentation ? PresentationSpringVelocity : DismissSpringVelocity,
options: isPresentation ? UIViewAnimationOptions.CurveEaseOut : [],
animations: {
if self.isPresentation {
self.presentViewController(presentedViewController, presentingViewController: presentingViewController)
} else {
self.dismissViewController(presentedViewController, presentingViewController: presentingViewController)
}
},
completion: { success in
transitionContext.completeTransition(success)
// !!!: We have to manually add `presentationView` due to a bug
// http://openradar.appspot.com/radar?id=5320103646199808
if !self.isPresentation {
UIApplication.sharedApplication().keyWindow?.addSubview(presentingView)
} else {
UIApplication.sharedApplication().keyWindow?.addSubview(presentedView)
}
})
}
func prepareViewControllerForPresentation(viewController: UIViewController, presentingViewController: UIViewController) { }
func presentViewController(viewController: UIViewController, presentingViewController: UIViewController) { }
func dismissViewController(viewController: UIViewController, presentingViewController: UIViewController) { }
}
此时尝试运行项目将导致构建成功。
如果我尝试在 NSObject
上实现协议(protocol)(为了符合 UIViewControllerAnimatedTransitioning
),我会收到段错误错误。
下面是我在呈现 AddNewMenuViewController
时用于 transitioningDelegate
的类,以及
TransitionControllerType
class AddNewMenuTransitionControllerDelegate: NSObject, UIViewControllerTransitioningDelegate {
func presentationControllerForPresentedViewController(presented: UIViewController, presentingViewController presenting: UIViewController, sourceViewController source: UIViewController) -> UIPresentationController? {
return AddNewMenuPresentationController(presentedViewController: presented, presentingViewController: presenting, blurStyle: .Dark)
}
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AddNewMenuTransitionController(presentation: true)
}
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return AddNewMenuTransitionController()
}
}
class AddNewMenuTransitionController: NSObject, TransitionControllerType {
var isPresentation: Bool
var presentationTransitionDuration: NSTimeInterval = 0.3
var dismissTransitionDuration: NSTimeInterval = 0.3
init(presentation: Bool = false) {
self.isPresentation = presentation
super.init()
}
}
为什么非通用版本会导致与通用版本相同的段错误?
最佳答案
当尝试确定您的 AddNewMenuTransitionController 类是否满足 UIViewControllerAnimatedTransitioning 协议(protocol)(这是您声明 TransitionControllerType 所必需的)时,我认为编译器无法识别通过扩展 TransitionControllerType 协议(protocol)添加的 animateTransition 的默认方法实现。
这对编译器的要求可能有点高,因为它本质上需要使用 TransitionControllerType 的默认实现来预先构建方法列表,同时它正在验证方法是否满足其要求之一。
如果您在 TransitionControllerType 的定义中不需要 UIViewControllerAnimatedTransitioning 而是将其显式添加到您的类定义中,则这可能会起作用(但我还没有尝试过)。
我确信这并不像您想要的那么干净,但是使用中间协议(protocol)的方法的间接默认实现目前对于编译器来说似乎太多了。
关于ios - 扩展 UIViewControllerAnimatedTransitioning 时出现段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34732921/
我想在navigationController的推送和弹出上制作一个过渡动画。但它的工作原理真的很奇怪。就像 1/5 倍一样,fromViewController 会淡出,但 toViewContro
做一个 simpel 转换但没有被调用我没有得到我在这里错过的东西。任何人都可以帮助我。没有收到任何错误或警告。 动画类-: import UIKit class CustomPresentAnima
我正在尝试使用 Pop-in 效果在 UIViewControllers 之间设置动画转换。 在我的 animateTransition(using transitionContext:) 函数中:
我已经在这里工作了几个小时,无法理解我做错了什么。我已经按照我之前的 Swift: Problems with custom UIView.transition? 中描述的 UITabBarContr
我已经创建了一个过渡并且它工作正常,除了我在模拟器中有时会出现黑角。此外,在 iPad Pro 中,如果我以全分辨率运行模拟器,我会得到一个完全黑屏。调整后的分辨率工作正常。你知道可能是什么问题吗?我
我试图使用 Swift 协议(protocol)提供 UIViewControllerAnimatedTransitioning 的通用实现,但每当我有一个符合该协议(protocol)的对象时,我都
我有一个 segue,它是通过一个按钮触发的,该按钮在当前上下文中模态显示另一个 View Controller 。我正在使用自定义类来自定义转换,它是这样的: class ShowAnimator:
在搜索如何在从一个 Controller 过渡到另一个 Controller 时执行自定义动画时,我发现了一些有关 UIViewControllerAnimatedTransitioning 的信息。
我已经为全屏显示的 Controller 实现了交互式关闭动画。 问题是每当我尝试关闭它时,状态栏都会出现 全屏 Controller 的 - (BOOL)prefersStatusBarHidden
我已经在 navigationController 上成功实现了 UIViewControllerAnimatedTransitioning,并且在 iOS 7 上有一个很好的自定义转换。 现在的问题
我在ViewController A中实现了这个方法 - (BOOL)prefersStatusBarHidden { return NO; } 我在 ViewController B 中实现了该
我正在尝试制作自定义演示动画,但 VC 是一个 MPMoviePlayerViewController。我正在学习本教程: 当我呈现 MPMoviePlayerViewController 时,一切正
自定义过渡对我来说相当陌生。我不得不将它们合并到我工作的最后一个项目中,并最终使用 UIViewControllerAnimatedTransitioning 协议(protocol)和自定义 seg
所以我开始着手创建自定义插入/弹出转换,第一次插入转换时一切正常,但是当我尝试插入另一个 View Controller 时,我根本看不到任何动画。 Here is a sample project
我试图在推送 UIViewController 时进行简单的动画转换,但似乎我遗漏了一些东西。 我将 subview 的快照从 fromViewController 动画化到 toViewContro
我正在尝试使用 UIViewcontrollerAnimatedTransitioning 为 PopUp ViewController 呈现动画。我已经创建了一个从 TableViewCell 到我
我刚刚花了最后几个小时来追踪一个恰好位于转换驱动程序对象中的错误,多次调用 interruptibleAnimator 方法,其中: 一个 UIViewPropertyAnimator 完成闭包包含对
将 View Controller 推送到 UINavigationController 时如何获得自定义转换 (iOS7)?我尝试在 UINavigationController 和我正在推送的 C
我今天刚用 Swift4 升级到 XCode9。我发现我的 UIViewControllerAnimatedTransitioning 不再按预期工作。这个动画的效果是fromView会缩小到0.95
我正在使用一些 UIViewController包含在 UINavigationController 中. 一个人会收到一个推送 segue来自UIButton在 storyboard 上, 然后使用
我是一名优秀的程序员,十分优秀!