ios - 将 View 放置在屏幕上 Swift

标签 ios swift uiview

我正在使用 PDF View 从 url 加载 pdf。但是,PDF View 覆盖整个屏幕。这就是段 Controller 消失的原因。 PDF View 应出现在段 Controller 下方。我应该怎么做才能使其显示在该段下方,而不是全屏?

class PDFController: UIViewController {
@IBOutlet weak var segmentedControl: UISegmentedControl!

  func fillWithYORUM() {
 if #available(iOS 11.0, *) {
                      let pdfView = PDFView(frame: self.view.bounds)
                      pdfView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
                            self.view.addSubview(pdfView)
                                pdfView.autoScales = true
                     let postURL = URL(string: self.pdfLink)
                    if postURL != nil {

                      pdfView.document = PDFDocument(url: postURL!)
                      print("postURL", postURL as Any)
                    }
                    else {
                    }
                  } else {
                  }
}

enter image description here

enter image description here

最佳答案

您可以在此处设置全屏 View 范围

let pdfView = PDFView(frame: self.view.bounds)

但你需要其中一个

let pdfView = PDFView(frame:self.view.frame.offsetBy(dx: 0, dy:segmentControl.frame.maxY)))

view.addSubview(pdfView)
pdfView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
  pdfView.topAnchor.constraint(equalTo: segment.bottomAnchor,constant:20.0),
  pdfView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  pdfView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
  pdfView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])

关于ios - 将 View 放置在屏幕上 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59293119/

相关文章:

ios - 如何在不使用google SDK和pod的情况下在ios中进行google身份验证?

multithreading - 在后台线程上将 UIVIew 渲染为图像的安全方法?

ios - 禁用和重新启用 Touch ID 时出现钥匙串(keychain)错误 -25300 (errSecItemNotFound)

iphone - 如何在 Core Text Programming 中设置字体大小和名称?

ios - 检查 key 是否存在于 NSDictionary 中

ios - 手势识别器在一段时间后没有响应

swift - 如何在命令行上使用和运行 Swift 2.3

c++ - 从 Blob OpenCV 侵 eclipse 文本

ios - Apple 是否设置 UIView 标签?

ios - UIView重新渲染布局时,不会触发draw函数