我正在开发一个iPhone应用程序,并创建了一个UIPageViewController (让我们称它为容器),它包含许多UIViewController页面(让我们称它们为子页)。子页转换样式为滚动。
现在,我喜欢做的是在容器的右上角创建一个按钮,而不是在子页中创建一个按钮。这样做的想法是,当子页面从一个页面滚动到另一个页面时,该按钮将保留在屏幕上。如果我在一个子页中创建该按钮,那么每个子页面都会有自己的按钮,并且该按钮将与子页一起滚动。我希望在不移动容器的情况下保留按钮,而子页滚动。
我尝试使用情节提要将按钮添加到容器中,但现在允许使用它。我不能把它放在那里,我怀疑原因是因为容器是UIPageViewController类型的。
我怎么才能用故事板做到这一点呢?
谢谢。
发布于 2014-11-23 04:09:01
发布于 2014-11-23 03:59:50
在代码中,将按钮添加到uipageviewcontroller控制器中。
发布于 2019-02-14 00:48:04
下面是一个使用故事板的解决方案。你必须做一些代码,但它是最小的
class TouchThroughView: UIView {
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
for subview in subviews {
if !subview.isHidden && subview.isUserInteractionEnabled && subview.point(inside: convert(point, to: subview), with: event) {
return true
}
}
return false
}
}您的PageViewControllerWill如下所示:
class MyPageViewController: UIPageViewController {
// step 3
@IBOutlet var touchThroughView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// your regular page View Controller implementation
// step 4
stationaryView.translatesAutoresizingMaskIntoConstraints = false
// step 5
self.view.addSubview(touchThroughView)
// Step 6
touchThroughView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
touchThroughView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
touchThroughView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
touchThroughView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
}
}你的故事板会是这样的:

https://stackoverflow.com/questions/27085414
复制相似问题