- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
答案:简单语法错误 - 设置委托(delegate)时,它应该读取 SomeNavigationController.delegate = self,而不是 SomeNavigationController.navigationController?.delegate = self
下面是创建导航 Controller 的基本 View Controller 。我将 self 声明为它的委托(delegate),并在该 View Controller 的扩展中遵守委托(delegate)的协议(protocol),并创建一个对象作为自定义动画师。但此导航堆栈中的 View Controller 不采用此动画;我错过了什么?
此导航堆栈的 Root View Controller 中或在此堆栈中推送和弹出的 View Controller 中是否需要存在任何代码?或者所有自定义动画代码都属于这里(在创建导航 Controller 的 View Controller 中)而我只是缺少一些东西?
创建 UINavigationController 的 View Controller
class BaseViewController: UIViewController {
override func loadView() {
buildNavigationController()
}
func buildNavigationController() {
let SomeNavigationControllerRoot = SomeViewController()
let SomeNavigationController = UINavigationController(rootViewController: SomeNavigationControllerRoot)
SomeNavigationController.delegate = self
view.addSubview(SomeNavigationController.view)
}
}
extension BaseViewController: UINavigationControllerDelegate {
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return CustomAnimator()
}
}
class CustomAnimator: NSObject, UIViewControllerAnimatedTransitioning {
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 1.0
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)
containerView.addSubview(toViewController!.view)
toViewController!.view.alpha = 0.0
UIView.animate(withDuration: 1.0, animations: {
toViewController!.view.alpha = 1.0
}, completion: { finished in
let cancelled = transitionContext.transitionWasCancelled
transitionContext.completeTransition(!cancelled)
})
}
}
UINavigationController 堆栈中的 Root View Controller
class SomeViewController: UIViewController, UINavigationControllerDelegate {
func pushToNext() {
let randomViewController = randomViewController()
navigationController?.pushViewController(randomViewController, animated: true)
}
}
最佳答案
如果你想使用自定义转换,你需要应用transitioningDelegate将 View Controller 的transitioningDelegate设置为您的自定义类并返回自定义动画 Controller 。
关于ios - 如何将 UINavigationControllerDelegate 连接到导航 Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45909010/
我已经建立了一个非常简单的项目,没有 Storyboard,一个窗口和一个 UINavigationController,其中包含一个普通的旧 UIViewController 作为 rootView
UINavigationControllerDelegate 只有 2 个委托(delegate)方法可以使用: navigationController:willShowViewController
更新到正确的版本,因为得到了答案。 我想在导航 View Controller 弹出/推送时做淡入/淡出动画,然后我实现一个 BaseViewController: class BaseViewCon
我的代码: 导航器.m - (void)newPushPage:(UIViewController *)controller { [self pushViewController:contro
我有一个 View Controller ,在其中实现 UIImagePickerDelegate 和 UINavigationControllerDelegate,以便从图库或相机获取图像。选择图像
我想为 UINavigation Controller 实现自定义动画。 我在 Appdelegate 中添加了一些属性: @interface MyAppDelegate : UIResponder
我正在尝试在从自定义 UINavigationController 类推送/弹出 viewController 时进行自定义转换。我正在实现 UINavigationControllerDelegat
我在 UINavigationController 堆栈中有一个用于推送和弹出事件的自定义动画转换,我只想将该自定义动画应用于特定的推送事件——例如,在推送 RandomViewController4
答案:简单语法错误 - 设置委托(delegate)时,它应该读取 SomeNavigationController.delegate = self,而不是 SomeNavigationControl
所以我开始着手创建自定义插入/弹出转换,第一次插入转换时一切正常,但是当我尝试插入另一个 View Controller 时,我根本看不到任何动画。 Here is a sample project
(XCode 8.1,Swift 3。github 中的示例 https://github.com/SuperTango/UINavigationControllerNoNavbar 在“byhand
短:实现 func navigationController(_ navigationController: UINavigationController, animationControllerFo
我正在尝试使用 UIImagePickerController 从图库中挑选一张图片。 如果我的 View Controller 没有提到 UINavigationControllerDelegate
class ViewController: UIViewController, UINavigationControllerDelegate { override func viewDid
有没有办法让 View Controller 从内部转换出来: - (void)navigationController:(UINavigationController *)navigationCon
DetailViewController MasterViewController ViewController 目前,我通过让 ViewController 类中的一个变量指向 DetailVi
func openGallery(sender: AnyObject) { var imagePicker = UIImagePickerController() imagePicke
我正在开发一个包含 WYPopoverController 的应用程序,它在应有的地方工作得很好。我想在两个 Controller 之间添加自定义动画,而不是内置 push/pop。 在包含 FROM
如果您拖动 UIViewController 的边缘以在 UINavigationController 中开始交互式弹出转换,当前下方的 UIViewController 具有 viewWillApp
弹出到不支持当前方向的 View Controller 时,未调用 UINavigationControllerDelegate 方法。 我有一个 UINavigationController 作为我
我是一名优秀的程序员,十分优秀!