在 pageController 中获取可见视图
Get visible view in pageController
我在不同的视图之间滚动,我在 rootViewController 中单击按钮想要呈现为图像。我想知道最好的方法是什么?是否可以从我的 contentViewController 检索可见视图,或者我是否需要通过获取可见视图索引以某种方式重新创建视图,然后访问等于该索引的对象?
回答'is it possible to retrieve the visible view from my contentViewController',不是真的。您需要在 CustomContentViewController
中设置一个 pageIndex
属性。在 didFinishAnimating
方法中跟踪它(您可以在其他帖子中找到更可靠的方法)。或者你可以直接跟踪 currentContentViewController
这只是一个非常简单的例子
func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
self.currentContentViewController = pageViewController.viewControllers!.last as! CustomContentViewController
self.currentPageIndex = self.currentContentViewController.pageIndex
}
如果要设置图片,那么
@IBAction func buttonTapped(sender: UIButton) {
self.currentContentViewController.imageView.image = UIImage("MyImage.png")
}
我在不同的视图之间滚动,我在 rootViewController 中单击按钮想要呈现为图像。我想知道最好的方法是什么?是否可以从我的 contentViewController 检索可见视图,或者我是否需要通过获取可见视图索引以某种方式重新创建视图,然后访问等于该索引的对象?
回答'is it possible to retrieve the visible view from my contentViewController',不是真的。您需要在 CustomContentViewController
中设置一个 pageIndex
属性。在 didFinishAnimating
方法中跟踪它(您可以在其他帖子中找到更可靠的方法)。或者你可以直接跟踪 currentContentViewController
这只是一个非常简单的例子
func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
self.currentContentViewController = pageViewController.viewControllers!.last as! CustomContentViewController
self.currentPageIndex = self.currentContentViewController.pageIndex
}
如果要设置图片,那么
@IBAction func buttonTapped(sender: UIButton) {
self.currentContentViewController.imageView.image = UIImage("MyImage.png")
}