[ad_1]
I am having a difficulty whereas transferring a view that comprises a SwiftUI view close to the sides of the display screen. The SwiftUI view strikes itself to keep away from being blocked by the secure space insets
I am utilizing UIKit to deal with dragging the view through UIHostingController and a UIPanGestureRecognizer . Here is the code
import UIKit
class ViewController: UIViewController {
var contentView: UIView!
override func viewDidLoad() {
tremendous.viewDidLoad()
// Do any further setup after loading the view.
let contentVc = UIHostingController(rootView: Content material())
addChild(contentVc)
contentView = contentVc.view
let contentHeight = contentView.sizeThatFits(view.bounds.measurement).peak
contentView.body = CGRect(x: 0, y: 200, width: view.bounds.width, peak: contentHeight)
view.addSubview(contentView)
contentVc.didMove(toParent: self)
let drag = UIPanGestureRecognizer(goal: self, motion: #selector(drag(_:)))
contentView.addGestureRecognizer(drag)
view.backgroundColor = .orange
}
var startingPoint = CGPoint.zero
@objc func drag(_ gesture: UIPanGestureRecognizer) {
change gesture.state {
case .started:
startingPoint = contentView.body.origin
case .modified:
let location = gesture.translation(in: view)
contentView.body.origin.y = startingPoint.y + location.y
default:
break
}
}
}
import SwiftUI
struct Content material: View {
var physique: some View {
VStack {
ForEach(0..<10) { i in
Textual content(String(i))
}
}
.background(Coloration.blue)
.padding(.vertical, 32)
.ignoresSafeArea()
}
}
What I am anticipating is the blue view to to not modify itself vertically (within the preview the blue view’s high padding is shrinking)
[ad_2]

