swift – ViewController幻灯片动画

swift – ViewController幻灯片动画,第1张

概述我想在tabswitch [1]创建一个类似iOS app facebook的动画.我已经尝试开发某种动画,出现的问题是旧的视图控制器直接在交换机上变得不可见,而不是在新控制器快速滑动时缓慢淡出. 我发现这个问题How to animate Tab bar tab switch with a CrossDissolve slide transition?,但正确的标记解决方案对我来说并不适用(它不 我想在tabswitch [1]创建一个类似iOS app facebook的动画.我已经尝试开发某种动画,出现的问题是旧的视图控制器直接在交换机上变得不可见,而不是在新控制器快速滑动时缓慢淡出.

我发现这个问题How to animate Tab bar tab switch with a CrossDissolve slide transition?,但正确的标记解决方案对我来说并不适用(它不是幻灯片,它是一个淡入淡出过渡).我还想得到的是向左或向右滑动以切换标签的功能.就像在旧版本的facebook上一样.

到目前为止我得到的是:

extension TabbarController: UITabbarControllerDelegate  {    func tabbarController(_ tabbarController: UITabbarController,shouldSelect vIEwController: UIVIEwController) -> Bool {        guard let fromVIEw = selectedVIEwController?.vIEw,let toVIEw = vIEwController.vIEw else { return false }        if fromVIEw != toVIEw {            toVIEw.transform = CGAffinetransform(translationX: -90,y: 0)            UIVIEw.animate(withDuration: 0.25,delay: 0.0,options: .curveEaseInOut,animations: {                toVIEw.transform = CGAffinetransform(translationX: 0,y: 0)            })        }; return true    }}
class TabbarController: UITabbarController {    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        delegate = self    }}

如何解决这个问题?

[1]
我非常想从Facebook应用程序中添加一个gif.问题是我不想审查视频,只是透露了太多的数据. (即使fb已经拥有它们).另外在youtube上我找不到合适的录音.请在iOS的fb应用程序中自行尝试.

您可以使用以下想法: https://samwize.com/2016/04/27/making-tab-bar-slide-when-selected/

此外,这里是更新到Swift 4.1的代码,我也删除了强制解包:

import UIKitclass MyTabbarController: UITabbarController {    overrIDe func vIEwDIDLoad() {        super.vIEwDIDLoad()        delegate = self    }}extension MyTabbarController: UITabbarControllerDelegate  {    func tabbarController(_ tabbarController: UITabbarController,shouldSelect vIEwController: UIVIEwController) -> Bool {        guard let tabVIEwControllers = tabbarController.vIEwControllers,let toIndex = tabVIEwControllers.index(of: vIEwController) else {            return false        }        animatetoTab(toIndex: toIndex)        return true    }    func animatetoTab(toIndex: Int) {        guard let tabVIEwControllers = vIEwControllers,let selectedVC = selectedVIEwController else { return }        guard let fromVIEw = selectedVC.vIEw,let toVIEw = tabVIEwControllers[toIndex].vIEw,let fromIndex = tabVIEwControllers.index(of: selectedVC),fromIndex != toIndex else { return }        // Add the toVIEw to the tab bar vIEw        fromVIEw.supervIEw?.addSubvIEw(toVIEw)        // position toVIEw off screen (to the left/right of fromVIEw)        let screenWIDth = UIScreen.main.bounds.size.wIDth        let scrollRight = toIndex > fromIndex        let offset = (scrollRight ? screenWIDth : -screenWIDth)        toVIEw.center = CGPoint(x: fromVIEw.center.x + offset,y: toVIEw.center.y)        // disable interaction during animation        vIEw.isUserInteractionEnabled = false        UIVIEw.animate(withDuration: 0.3,usingSpringWithdamPing: 1,initialSpringVeLocity: 0,options: .curveEaSEOut,animations: {                        // SlIDe the vIEws by -offset                        fromVIEw.center = CGPoint(x: fromVIEw.center.x - offset,y: fromVIEw.center.y)                        toVIEw.center = CGPoint(x: toVIEw.center.x - offset,y: toVIEw.center.y)        },completion: { finished in            // Remove the old vIEw from the tabbar vIEw.            fromVIEw.removeFromSupervIEw()            self.selectedindex = toIndex            self.vIEw.isUserInteractionEnabled = true        })    }}

因此,您需要继承UITabbarController并且还必须编写动画部分,您可以调整动画选项(延迟,持续时间等).

我希望它有所帮助,欢呼!

总结

以上是内存溢出为你收集整理的swift – ViewController幻灯片动画全部内容,希望文章能够帮你解决swift – ViewController幻灯片动画所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1089974.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存