gpt4 book ai didi

iOS swift : Transition Animation on same View Controller

转载 作者:可可西里 更新时间:2023-10-31 23:44:49 25 4
gpt4 key购买 nike

我怎样才能在单个 View Controller 上获得过渡动画效果(如页面幻灯片) - 这样看起来我正在过渡到一个新页面/ Controller (尽管在同一个 View 中只有数据发生变化)?

例如:我有一个 UIViewController,它有 Previous 和 Next 按钮。单击下一步这些按钮时,不同的标题和图像将显示在“相同UIViewController 上。

我知道这可以通过 UIPageViewController 来完成 - 但我是 iOS 的新手,发现以这种方式实现相当困难。

最佳答案

我也有同样的情况。但是因为我们不希望有复杂的幻灯片动画,所以我不会实现 UIPageViewController。相反,我提出了以下解决方案:

  • 想法是创建快照 View 并在其上启动动画,同时在用户开始滑动时使用新数据更新 View 。通过这样做,我们可以让人感觉我们正在转换到另一个 View 。

  • 下面的示例代码是用 Xamarin.iOS 编写的,但我相信它可以很容易地转移到 Swift/Obj-C:

            UIView snapShotView = View.SnapshotView(false); // Create snapshot for the view (I assumed that View is the container)
    View.Add(snapShotView);
    snapShotView.Frame = View.Frame; //Add snapshot and set its frame so the snapshot will be overlapped the original View

    CGRect snapshotEndFrame = snapShotView.Frame;
    snapshotEndFrame.X = -snapShotView.Frame.Width;

    UIView.Animate(0.7, 0, UIViewAnimationOptions.CurveEaseInOut,
    () =>
    {
    //Load new data to your View
    ...

    //Animate the snapshot view
    snapShotView.Frame = snapshotEndFrame;
    },
    () =>
    {
    //Remove Snap Shot View after doing animation to prevent memory leak
    snapShotView.RemoveFromSuperview();
    snapShotView.Dispose();
    });

关于iOS swift : Transition Animation on same View Controller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30466168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com