- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在这里工作了几个小时,无法理解我做错了什么。我已经按照我之前的 Swift: Problems with custom UIView.transition? 中描述的 UITabBarControllerDelegate
设置了自定义选项卡栏 Controller 转换。
我不使用普通的 Storyboard 标签栏按钮,我以编程方式切换 selectedIndex。我的问题是只有这个实现了:
func tabBarController(_ tabBarController: UITabBarController, animationControllerForTransitionFrom fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let animator = ModalTransition()
animator.fromView = fromVC.view
animator.toView = toVC.view
return animator
}
索引的动画和切换仅每隔一次发生。我有自定义按钮来切换索引,每隔一段时间,单击切换按钮时没有任何反应。这是我的动画:
//
// ModalTransition.swift
// Adventures In Design
//
// Created by Skylar Thomas on 8/28/17.
//
import UIKit
class ModalTransition: NSObject, UIViewControllerAnimatedTransitioning {
weak var transitionContext: UIViewControllerContextTransitioning?
var fromView = UIView()
var toView = UIView()
var duration = 1.1
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return 1
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
containerView.addSubview(toView)
containerView.sendSubview(toBack: toView)
print("ANIMATING")
UIView.animate(withDuration: duration, delay: 0.0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.0, options: .curveLinear, animations: {
self.fromView.center.y += 900
}, completion: {
finished in
//only works every OTHER click
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
self.fromView.center.y -= 900
})
}
}
这是什么原因造成的?是不是什么东西
最佳答案
我认为您没有分配 toView 和 FromView。尝试这样的事情
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
let fromView = fromViewController.view
let toView = toViewController.view
let container = transitionContext.containerView
container.addSubview(toView!)
// Replace your animations here
toView?.frame = transitionContext.finalFrame(for: toViewController)
toView?.alpha = 0
let duration = self.transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, delay: 0, options: .curveEaseInOut, animations: {
toView?.alpha = 1
fromView?.alpha = 0
}, completion: { finished in
toView?.alpha = 1.0
fromView?.alpha = 1
fromView?.removeFromSuperview()
transitionContext.completeTransition(true)
})
}
关于ios - UIViewControllerAnimatedTransitioning 每隔一段时间才有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45945182/
我想在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 上, 然后使用
我是一名优秀的程序员,十分优秀!