Skip to content

Instantly share code, notes, and snippets.

View BLCKBIRDS's full-sized avatar

BLCKBIRDS BLCKBIRDS

View GitHub Profile
print("Use Gists to show your code snippets")
//
// FoodData.swift
// C2FoodDeliveryP1
//
// Created by Andreas Schultz on 28.09.19.
// Copyright © 2019 Andreas Schultz. All rights reserved.
//
import Foundation
var body: some View {
NavigationView {
//...
}
.offset(y: -keyboardResponder.currentHeight*0.9)
}
struct ContentView: View {
//...
@ObservedObject var keyboardResponder = KeyboardResponder()
var body: some View {
//...
}
}
@objc func keyBoardWillShow(notification: Notification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
withAnimation {
currentHeight = keyboardSize.height
}
}
}
@objc func keyBoardWillHide(notification: Notification) {
withAnimation {
init(center: NotificationCenter = .default) {
_center = center
//4. Tell the notification center to listen to the system keyboardWillShow and keyboardWillHide notification
_center.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
_center.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
}
class KeyboardResponder: ObservableObject {
//...
var _center: NotificationCenter
init(center: NotificationCenter = .default) {
_center = center
}
class KeyboardResponder: ObservableObject {
@Published var currentHeight: CGFloat = 0
}
import Foundation
import SwiftUI
class KeyboardResponder: ObservableObject {
}
let contacts = [
Contact(imageName: "hollyHuey", name: "Holly F. Huey", phone: "+1(242)-8110134", email: "hollyhuey@yeilmail.com", address: "242 Wildrose River 16040 Louisiana"),
Contact(imageName: "roseAcker", name: "Rose Acker", phone: "+1(656)-1881047", email: "roseacker@neymail.com", address: "249 Modoc Half 75290 Michigan"),
Contact(imageName: "leonardoLongNecker", name: "Leonardo Longnecker", phone: "+1(545)-3442899", email: "cbleonardo1@zuimail.com", address: "952 Baker Haggerty 90562 Missouri"),
Contact(imageName: "quentinJoplin", name: "Quentin F. Joplin", phone: "+1(434)-7448466", email: "cfjoplin5@neymail.com", address: "176 Flanigan Road 49223 Mississippi"),
Contact(imageName: "christineClapper", name: "Christine Clapper", phone: "+1(141)-5115553", email: "dachristine0@vuomail.com", address: "635 Prospect River 58641 Kansas"),
Contact(imageName: "joyCordon", name: "Joy Cordon", phone: "+1(353)-0663954", email: "bvjoy21@ypmail.com", address: "763 University Trail 81701 Wisco