制作像Apple的主屏幕一样的UIView

问题描述 投票:0回答:1

我正在尝试创建一个像Apple的跳板(所有应用程序所在的位置)的视图,因此我可以向右或向左滑动并显示另一组项目。我主要遇到约束问题,并且所有图标都在所有屏幕尺寸上正常显示。我只是使用一个基本的UIView控制器来尝试完成这个。使用像Apple的跳板这样的图像数组的约束的最佳方法是什么?

谢谢你的帮助。

storyboard xcode8 springboard
1个回答
0
投票

在故事板中,我拖了一个UIPageViewController和两个UIViewController。我已将UIPageViewController子类化为MyPageViewController

其余的由MyPageViewController.swift中的代码完成:

override func viewDidLoad() {
    super.viewDidLoad()

    // can't be done in storyboard (-_-)
    delegate = self
    datasource = self
    setViewControllers([page1, page2], direction: .forward, animated: false, completion: nil)
}

(其中page1page2是你的故事板的另外两个UIViewController)

如果您想知道如何获取page1(在storyboard中设置标识符之后):

let page1 = UIStoryboard(name: "MyStoryboard", bundle: nil).instantiateViewController(withIdentifier: "page1")
© www.soinside.com 2019 - 2024. All rights reserved.