This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIApplication: UIGestureRecognizerDelegate { | |
public func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | |
return false // set to `false` if you don't want to detect tap during other gestures | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UIApplication { | |
func addTapGestureRecognizer() { | |
guard let window = windows.first else { return } | |
let tapGesture = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing)) | |
tapGesture.cancelsTouchesInView = false | |
tapGesture.delegate = self | |
tapGesture.name = "MyTapGesture" | |
window.addGestureRecognizer(tapGesture) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
VStack { | |
TextView("", $myText) | |
} | |
.onTapGesture { | |
self.dismissKeyboard() | |
} | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if canImport(UIKit) | |
extension View { | |
func hideKeyboard() { | |
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) | |
} | |
} | |
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FormViewFix1: View { | |
@State var name = "" | |
@State var yearsExpereince: Int = 0 | |
var body: some View { | |
NavigationView { | |
Form { | |
Section(header: Text("Applicant Info"), content: { | |
HStack { | |
Text("Name:") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController { | |
@IBOutlet weak var textField: UITextField! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard)) | |
self.view.addGestureRecognizer(tapGesture) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Name | Type | Range | Default | |
---|---|---|---|---|
.maximumObservations | Int | [0...] | 1 | |
.minimumAspectRatio | Float | [0.0...1.0] | 0.5 | |
.maximumAspectRatio | Float | [0.0...1.0] | 0.5 | |
.minimumSize | Float | [0.0...1.0] | 0.2 | |
.quadratureTolerance | Float | [0.0...45.0] | 30.0 | |
.minimumConfidence | Float | [0.0...1.0] | 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func completedVisionRequest(_ request: VNRequest?, error: Error?) { | |
// Only proceed if a rectangular image was detected. | |
guard let rectangles = request?.results as? [VNRectangleObservation] else { | |
guard let error = error else { return } | |
print("Error: Rectangle detection failed - Vision request returned an error. \(error.localizedDescription)") | |
return | |
} | |
// do stuff with your rectangles | |
for rectangle in rectangles { | |
print(rectangle.boundingBox) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let request = VNDetectRectanglesRequest { request, error in | |
self.completedVisionRequest(request, error: error) | |
} |