我已经设置了具有 2 个视图的 PageViewControll。我可以在视图之间移动,并且 pageControl(点)对应于正确的页面 - 但是点击点还不能滚动到正确的视图。
我在这里找到了一些关于如何创建该函数的答案,但无法成功实现以使其工作。页面控制器的代码如下(没有点击功能)完整的代码是:
func configurePageControl() {
pageControl = UIPageControl(frame: CGRect(x: 0,y: UIScreen.main.bounds.maxY - 50,width: UIScreen.main.bounds.width,height: 50))
self.pageControl.numberOfPages = viewControllerList.count
self.pageControl.currentPage = 0
self.pageControl.alpha = 0.5
self.pageControl.tintColor = UIColor.white
self.pageControl.pageIndicatorTintColor = UIColor.black
self.pageControl.currentPageIndicatorTintColor = UIColor.white
self.view.addSubview(pageControl)
}
@IBAction func pageControltapped(_ sender: Any) {
guard let pageControl = sender as? UIPageControl else { return }
let selectedPage = pageControl.currentPage
self.setViewControllers([viewControllerList[selectedPage]], direction: .forward, animated: true, completion: nil)
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!!
我是 swift 编码的新手(以及一般编码的新手) - 并且正在努力将约束应用于Lottie动画。
我能够让它在屏幕上居中,但不能让动画帧根据屏幕尺寸改变它的大小,保持它的纵横比。
目前大小为 250x250,但我希望根据屏幕大小调整大小。任何帮助都感激不尽。
override func viewDidLoad() {
super.viewDidLoad()
let animationView = LOTAnimationView(name: "clock")
animationView.frame = CGRect(x: self.view.frame.width / 2 - 125, y: self.view.frame.height / 2 - 125, width: 250, height: 250)
animationView.contentMode = .scaleAspectFill
animationView.loopAnimation = true
self.view.addSubview(animationView)
view.sendSubviewToBack(animationView)
animationView.play()
}
Run Code Online (Sandbox Code Playgroud)