Как исправить Gesturerecognizer из -за Pdfkit, сломав пейджинг в новой версии iOS26?IOS

Программируем под IOS
Ответить
Anonymous
 Как исправить Gesturerecognizer из -за Pdfkit, сломав пейджинг в новой версии iOS26?

Сообщение Anonymous »

У меня был проект отлично, где мне нужно было делать вещи с формами PDF, черта на первом месте и т. Д. Поскольку Apple - все закрыто, мне нужно было стать немного хакерским. В любом случае, у меня есть проблема со времени нового обновления iOS 26, которое разбивает поведение. Я очень упростил код в демонстрационный проект, где вы можете быстро увидеть, что не так. Я застрял на первой странице. Я не знаю, что делать, пробовал много вещей, но ничего не работает. Кто -нибудь достаточно опытный, чтобы помочь мне? < /P>

Код: Выделить всё

import UIKit
import PDFKit
import SwiftUI

class PDFViewController: UIViewController {

var pdfView: PDFView!
var gestureHandler: GestureHandler!

override func viewDidLoad() {
super.viewDidLoad()
setupPDFView()
setupGestureHandler()
loadPDF()
}

private func setupPDFView() {
pdfView = PDFView(frame: view.bounds)

// Your exact configuration
pdfView.autoScales = true
pdfView.pageShadowsEnabled = false
pdfView.backgroundColor = .white
pdfView.displayMode = .singlePage

view.addSubview(pdfView)

// Setup constraints
pdfView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
pdfView.topAnchor.constraint(equalTo: view.topAnchor),
pdfView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
pdfView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
pdfView.bottomAnchor.constraint(equalTo: view.bottomAnchor)
])
}

private func setupGestureHandler() {
gestureHandler = GestureHandler(pdfView: pdfView)
gestureHandler.setupSwipeGestures(on: view)
}

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

print("📄 Current state: Page \(currentIndex + 1) of \(totalPages)")
print("👆 Swipe direction: \(gesture.direction == .left ? "LEFT (next)" : "RIGHT (previous)")")

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")
}

default:
print("🤷‍♂️ Unknown swipe direction")
break
}
}
}

struct PDFViewerRepresentable: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> PDFViewController {
return PDFViewController()
}

func updateUIViewController(_ uiViewController: PDFViewController, context: Context) {
// No updates needed
}
}
Вы можете также посмотреть на код здесь: https://github.com/vallezw/swift-bug-ios26образное.>

Подробнее здесь: https://stackoverflow.com/questions/797 ... e-new-ios2
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»