У меня был проект отлично, где мне нужно было делать вещи с формами PDF, черта на первом месте и т. Д. Поскольку Apple - все закрыто, мне нужно было стать немного хакерским. В любом случае, у меня есть проблема со времени нового обновления iOS 26, которое разбивает поведение. Я очень упростил код в демонстрационный проект, где вы можете быстро увидеть, что не так. Я застрял на первой странице. Я не знаю, что делать, пробовал много вещей, но ничего не работает. Кто -нибудь достаточно опытный, чтобы помочь мне? < /P>
У меня был проект отлично, где мне нужно было делать вещи с формами PDF, черта на первом месте и т. Д. Поскольку Apple - все закрыто, мне нужно было стать немного хакерским. В любом случае, у меня есть проблема со времени нового обновления iOS 26, которое разбивает поведение. Я очень упростил код в демонстрационный проект, где вы можете быстро увидеть, что не так. Я застрял на первой странице. Я не знаю, что делать, пробовал много вещей, но ничего не работает. Кто -нибудь достаточно опытный, чтобы помочь мне? < /P> [code]import UIKit import PDFKit import SwiftUI
class PDFViewController: UIViewController {
var pdfView: PDFView! var gestureHandler: GestureHandler!
private func loadPDF() { if let path = Bundle.main.path(forResource: "sonate12", ofType: "pdf"), let document = PDFDocument(url: URL(fileURLWithPath: path)) { pdfView.document = document } else { print("Could not find sonate12.pdf in bundle") } } }
class GestureHandler {
private weak var pdfView: PDFView?
init(pdfView: PDFView) { self.pdfView = pdfView }
func setupSwipeGestures(on view: UIView) { // Left swipe - go to next page let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:))) leftSwipe.direction = .left view.addGestureRecognizer(leftSwipe)
// Right swipe - go to previous page let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(handleSwipe(_:))) rightSwipe.direction = .right view.addGestureRecognizer(rightSwipe) }
@objc private func handleSwipe(_ gesture: UISwipeGestureRecognizer) { guard let pdfView = pdfView, let document = pdfView.document, let currentPage = pdfView.currentPage else { print("🚫 No PDF view, document, or current page available") return }
let currentIndex = document.index(for: currentPage) let totalPages = document.pageCount
switch gesture.direction { case .left: // Next page guard currentIndex < document.pageCount - 1 else { print("🚫 Already on last page (\(currentIndex + 1)), cannot go forward") return }
let nextPage = document.page(at: currentIndex + 1) if let page = nextPage { print("➡️ Going to page \(currentIndex + 2)") pdfView.go(to: page) pdfView.setNeedsDisplay() pdfView.layoutIfNeeded() // Check if navigation actually worked DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { if let newCurrentPage = pdfView.currentPage { let newIndex = document.index(for: newCurrentPage) print("✅ Navigation result: Now on page \(newIndex + 1)") if newIndex == currentIndex { print("⚠️ WARNING: Page didn't change visually!") } } } } else { print("🚫 Could not get next page object") }
case .right: // Previous page guard currentIndex > 0 else { print("🚫 Already on first page (1), cannot go back") return }
let previousPage = document.page(at: currentIndex - 1) if let page = previousPage { print("⬅️ Going to page \(currentIndex)") pdfView.go(to: page) pdfView.setNeedsDisplay() pdfView.layoutIfNeeded() let bounds = pdfView.bounds pdfView.bounds = CGRect(x: bounds.origin.x, y: bounds.origin.y, width: bounds.width + 0.01, height: bounds.height) pdfView.bounds = bounds
// Check if navigation actually worked DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { if let newCurrentPage = pdfView.currentPage { let newIndex = document.index(for: newCurrentPage) print("✅ Navigation result: Now on page \(newIndex + 1)") if newIndex == currentIndex { print("⚠️ WARNING: Page didn't change visually!") } } } } else { print("🚫 Could not get previous page object") }
func updateUIViewController(_ uiViewController: PDFViewController, context: Context) { // No updates needed } } [/code] Вы можете также посмотреть на код здесь: https://github.com/vallezw/swift-bug-ios26образное.>