Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS Swift:如何实现像用户界面一样的一叠卡片?_Ios_Swift_Swift4 - Fatal编程技术网

iOS Swift:如何实现像用户界面一样的一叠卡片?

iOS Swift:如何实现像用户界面一样的一叠卡片?,ios,swift,swift4,Ios,Swift,Swift4,我试图实现以下设计,其中四个不同的视图控制器将背靠背堆叠。参考图片如下- 每个视图控制器将动态地具有具有不同数据的表视图。可以通过从右侧滑动来切换视图控制器 我知道UIPageViewController适合这种分页方法。但是,我担心这种堆叠页面视图是否可以实现 我还没有开始做任何事情,我需要一些想法来开始。首先,有可能做到这一点吗 如果不够清楚,请告诉我。谢谢。正如我在评论中建议的那样,您可以创建一个容器视图控制器,在其中添加子视图控制器。如何呈现和移除它们取决于您。我添加了一个滑动手势,将它

我试图实现以下设计,其中四个不同的视图控制器将背靠背堆叠。参考图片如下-

每个视图控制器将动态地具有具有不同数据的表视图。可以通过从右侧滑动来切换视图控制器

我知道UIPageViewController适合这种分页方法。但是,我担心这种堆叠页面视图是否可以实现

我还没有开始做任何事情,我需要一些想法来开始。首先,有可能做到这一点吗


如果不够清楚,请告诉我。谢谢。

正如我在评论中建议的那样,您可以创建一个容器视图控制器,在其中添加子视图控制器。如何呈现和移除它们取决于您。我添加了一个滑动手势,将它们逐个从ChildViewController阵列中删除,但您可以通过动画等进行详细说明。以下是示例:

import UIKit
class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        let swipeGesturRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(didSwipe))
        swipeGesturRecognizer.direction = .left
        view.addGestureRecognizer(swipeGesturRecognizer)

        var index = 0
        let amount = 5
        while index < amount {
            let childViewController = UIViewController()
            childViewController.view
            .translatesAutoresizingMaskIntoConstraints = true
            let hue = 1.0 / CGFloat(index)
            childViewController.view.backgroundColor = UIColor(hue: hue, saturation: 0.5, brightness: 0.5, alpha: 1)
            childViewController.view.frame = self.view.bounds.insetBy(dx: CGFloat(amount - index) * 10, dy: 80.0).offsetBy(dx: 0.0, dy: -CGFloat(amount - index) * 10.0)
            childViewController.view.layer.borderColor = UIColor.blue.cgColor
            childViewController.view.layer.borderWidth = 1.0
            self.view.addSubview(childViewController.view)
            self.addChildViewController(childViewController)
            childViewController.didMove(toParentViewController: self)
            index += 1
        }
    }

    // Removes child view controlelrs one by one when swiped left
    @objc func didSwipe() {
        guard let childViewController = childViewControllers.last else {
            return
        }
        childViewController.willMove(toParentViewController: nil)
        childViewController.view.removeFromSuperview()
        childViewController.removeFromParentViewController()
    }
}

它与:?我建议创建一个容器视图控制器,并向其中添加子视图控制器。好的@AuRis。但是,如何使用容器视图将页面显示在彼此的顶部?核心动画和仿射变换应该能够做到这一点。好的,有用的信息。但是如果你能发布一些代码片段,那会很有帮助吗?我会试试这个,让你知道。多谢了,如果我想修改它以创建一个无限循环,而不是在滑动时删除子视图,将其推到最后一个索引,我应该怎么做?有什么提示吗?