Commit 3e972c5f authored by yqz's avatar yqz

1111111

parent d68129c2
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Google@2x 1@2x(1).png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Google@2x 1@3x(1).png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "Google@2x 1@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Google@2x 1@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
...@@ -68,7 +68,7 @@ class SpeakTitleView: UIView { ...@@ -68,7 +68,7 @@ class SpeakTitleView: UIView {
make.top.equalToSuperview().offset(Dev.safeAreaInsets.top) make.top.equalToSuperview().offset(Dev.safeAreaInsets.top)
} }
backBtn.snp.makeConstraints { make in backBtn.snp.makeConstraints { make in
make.left.equalToSuperview().inset(marginLR) make.left.equalToSuperview().inset(marginLR-4)
make.centerY.equalTo(titleLabel) make.centerY.equalTo(titleLabel)
} }
} }
......
...@@ -23,6 +23,7 @@ enum SpeakEasyAssociatedKeys : UInt32 { ...@@ -23,6 +23,7 @@ enum SpeakEasyAssociatedKeys : UInt32 {
case labelTextTap = 0x10001 case labelTextTap = 0x10001
case navigationAniKey = 0x01122 case navigationAniKey = 0x01122
case labelTextCutomFont = 0x01102 case labelTextCutomFont = 0x01102
case windowkeyboardKey = 0x120323
} }
protocol CutomFontProtocol : NSObjectProtocol { protocol CutomFontProtocol : NSObjectProtocol {
......
...@@ -10,8 +10,11 @@ import UIKit ...@@ -10,8 +10,11 @@ import UIKit
extension String { extension String {
func isValidEmail() -> Bool {
let emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}"
let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailRegex)
return emailPredicate.evaluate(with: self)
}
func localJson(_ fileName:String) -> String? { func localJson(_ fileName:String) -> String? {
let path = Bundle.main.path(forResource: fileName, ofType: "json") let path = Bundle.main.path(forResource: fileName, ofType: "json")
......
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
import UIKit import UIKit
extension UIButton : CutomFontProtocol { extension UIButton {
func setCutomFonts() { override func setCutomFonts() {
if cutomFont >= 0 { if cutomFont >= 0 {
switch cutomFont { switch cutomFont {
case 0: case 0:
......
...@@ -26,7 +26,7 @@ extension UILabel : CutomFontProtocol { ...@@ -26,7 +26,7 @@ extension UILabel : CutomFontProtocol {
} }
func setCutomFonts() { override func setCutomFonts() {
if cutomFont >= 0 { if cutomFont >= 0 {
switch cutomFont { switch cutomFont {
case 0: case 0:
......
...@@ -13,7 +13,11 @@ fileprivate var cutomFontsKey = SpeakEasyAssociatedKeys.labelTextCutomFont.rawVa ...@@ -13,7 +13,11 @@ fileprivate var cutomFontsKey = SpeakEasyAssociatedKeys.labelTextCutomFont.rawVa
@IBDesignable @IBDesignable
extension UIView { extension UIView : CutomFontProtocol {
@objc func setCutomFonts() {
}
@objc public var callblack:((Any)->Void)? { @objc public var callblack:((Any)->Void)? {
set { set {
...@@ -123,6 +127,9 @@ extension UIView { ...@@ -123,6 +127,9 @@ extension UIView {
@IBInspectable var cutomFont:Int { @IBInspectable var cutomFont:Int {
set { set {
objc_setAssociatedObject(self, &cutomFontsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) objc_setAssociatedObject(self, &cutomFontsKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.02) {
self.setCutomFonts()
}
} }
get { get {
return objc_getAssociatedObject(self, &cutomFontsKey) as? Int ?? -1 return objc_getAssociatedObject(self, &cutomFontsKey) as? Int ?? -1
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23727" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23727" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_12" orientation="portrait" appearance="light"/> <device id="retina4_0" orientation="portrait" appearance="light"/>
<dependencies> <dependencies>
<deployment identifier="iOS"/> <deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23721"/> <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23721"/>
...@@ -16,20 +16,20 @@ ...@@ -16,20 +16,20 @@
</placeholder> </placeholder>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/> <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sp-bg" translatesAutoresizingMaskIntoConstraints="NO" id="5SM-Lp-0MM"> <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="sp-bg" translatesAutoresizingMaskIntoConstraints="NO" id="5SM-Lp-0MM">
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/> <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
</imageView> </imageView>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aYT-y7-hf8"> <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="aYT-y7-hf8">
<rect key="frame" x="0.0" y="172" width="393" height="680"/> <rect key="frame" x="0.0" y="74" width="320" height="494"/>
<subviews> <subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8r0-nd-l8p"> <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="8r0-nd-l8p">
<rect key="frame" x="0.0" y="0.0" width="393" height="500"/> <rect key="frame" x="0.0" y="0.0" width="320" height="500"/>
<subviews> <subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Get Unlimited Access" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GRD-E5-C2J"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Get Unlimited Access" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="GRD-E5-C2J">
<rect key="frame" x="24" y="0.0" width="345" height="21"/> <rect key="frame" x="24" y="0.0" width="272" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/> <nil key="textColor"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
</userDefinedRuntimeAttributes> </userDefinedRuntimeAttributes>
</label> </label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Learning, progress, improvement" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ynQ-dm-w6L"> <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Learning, progress, improvement" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ynQ-dm-w6L">
<rect key="frame" x="24" y="29" width="345" height="21"/> <rect key="frame" x="24" y="29" width="272" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/> <fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.54490858843537415" colorSpace="custom" customColorSpace="calibratedRGB"/> <color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="0.54490858843537415" colorSpace="custom" customColorSpace="calibratedRGB"/>
<nil key="highlightedColor"/> <nil key="highlightedColor"/>
...@@ -78,13 +78,31 @@ ...@@ -78,13 +78,31 @@
</constraints> </constraints>
</scrollView> </scrollView>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Khu-4S-MSZ"> <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Khu-4S-MSZ">
<rect key="frame" x="24" y="122" width="40" height="40"/> <rect key="frame" x="24" y="24" width="40" height="40"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/> <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" image="sp-Close"/> <state key="normal" image="sp-Close"/>
<connections> <connections>
<action selector="SpeakCloseTaps:" destination="-1" eventType="touchUpInside" id="Ehx-8a-Yrb"/> <action selector="SpeakCloseTaps:" destination="-1" eventType="touchUpInside" id="Ehx-8a-Yrb"/>
</connections> </connections>
</button> </button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="B7F-jV-sWR">
<rect key="frame" x="214" y="27" width="82" height="34"/>
<color key="backgroundColor" red="0.10980392156862745" green="0.14901960784313725" blue="0.20392156862745098" alpha="0.29525403911564635" colorSpace="custom" customColorSpace="calibratedRGB"/>
<inset key="contentEdgeInsets" minX="10" minY="6" maxX="10" maxY="6"/>
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
<state key="normal" title="Restore"/>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="number" keyPath="cutomFont">
<integer key="value" value="1"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="fontSize">
<real key="value" value="14"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="number" keyPath="corners">
<real key="value" value="17"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
</button>
</subviews> </subviews>
<viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/> <viewLayoutGuide key="safeArea" id="fnl-2z-Ty3"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/> <color key="backgroundColor" systemColor="systemBackgroundColor"/>
...@@ -92,7 +110,9 @@ ...@@ -92,7 +110,9 @@
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="aYT-y7-hf8" secondAttribute="trailing" id="1vp-dD-GTQ"/> <constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="aYT-y7-hf8" secondAttribute="trailing" id="1vp-dD-GTQ"/>
<constraint firstItem="5SM-Lp-0MM" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5Fy-iV-kqk"/> <constraint firstItem="5SM-Lp-0MM" firstAttribute="top" secondItem="i5M-Pr-FkT" secondAttribute="top" id="5Fy-iV-kqk"/>
<constraint firstItem="5SM-Lp-0MM" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="AjH-kD-Mkl"/> <constraint firstItem="5SM-Lp-0MM" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="AjH-kD-Mkl"/>
<constraint firstItem="B7F-jV-sWR" firstAttribute="centerY" secondItem="Khu-4S-MSZ" secondAttribute="centerY" id="Bw5-S7-H2b"/>
<constraint firstItem="5SM-Lp-0MM" firstAttribute="trailing" secondItem="fnl-2z-Ty3" secondAttribute="trailing" id="OXa-HW-56J"/> <constraint firstItem="5SM-Lp-0MM" firstAttribute="trailing" secondItem="fnl-2z-Ty3" secondAttribute="trailing" id="OXa-HW-56J"/>
<constraint firstItem="fnl-2z-Ty3" firstAttribute="trailing" secondItem="B7F-jV-sWR" secondAttribute="trailing" constant="24" id="OkQ-Ok-JoH"/>
<constraint firstItem="aYT-y7-hf8" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="P4U-QH-Kwb"/> <constraint firstItem="aYT-y7-hf8" firstAttribute="leading" secondItem="fnl-2z-Ty3" secondAttribute="leading" id="P4U-QH-Kwb"/>
<constraint firstAttribute="bottom" secondItem="5SM-Lp-0MM" secondAttribute="bottom" id="jDz-gg-Zym"/> <constraint firstAttribute="bottom" secondItem="5SM-Lp-0MM" secondAttribute="bottom" id="jDz-gg-Zym"/>
<constraint firstItem="Khu-4S-MSZ" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" constant="4" id="pkS-QV-Hi6"/> <constraint firstItem="Khu-4S-MSZ" firstAttribute="top" secondItem="fnl-2z-Ty3" secondAttribute="top" constant="4" id="pkS-QV-Hi6"/>
......
...@@ -12,8 +12,6 @@ import YYText ...@@ -12,8 +12,6 @@ import YYText
class SpeakEleLoginGuideCtr: SpeakEleBaseViewCtr { class SpeakEleLoginGuideCtr: SpeakEleBaseViewCtr {
@IBOutlet weak var SpeakDescLabel: UILabel! @IBOutlet weak var SpeakDescLabel: UILabel!
@IBOutlet weak var speakLetsGo: SpeakEleButton!
@IBOutlet weak var speakLoginBtn: UIButton!
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -21,9 +19,6 @@ class SpeakEleLoginGuideCtr: SpeakEleBaseViewCtr { ...@@ -21,9 +19,6 @@ class SpeakEleLoginGuideCtr: SpeakEleBaseViewCtr {
override func viewWillAppear(_ animated: Bool) { override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated) super.viewWillAppear(animated)
SpeakDescLabel.setCutomFonts()
speakLetsGo.setCutomFonts()
speakLoginBtn.setCutomFonts()
setDescription() setDescription()
} }
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SpeakEleLoginGuideCtr" customModule="SpeakEasyLearnEnglish" customModuleProvider="target"> <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="SpeakEleLoginGuideCtr" customModule="SpeakEasyLearnEnglish" customModuleProvider="target">
<connections> <connections>
<outlet property="SpeakDescLabel" destination="jGO-Du-a3k" id="mxV-nA-Nwk"/> <outlet property="SpeakDescLabel" destination="jGO-Du-a3k" id="mxV-nA-Nwk"/>
<outlet property="speakLetsGo" destination="Zwf-M5-Hrt" id="GqW-aT-1s1"/>
<outlet property="speakLoginBtn" destination="GOS-gl-Ilh" id="951-M8-75o"/>
<outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/>
</connections> </connections>
</placeholder> </placeholder>
......
...@@ -6,13 +6,122 @@ ...@@ -6,13 +6,122 @@
// //
import UIKit import UIKit
import AuthenticationServices
class SpeakEleLoginViewCtr: SpeakEleBaseViewCtr {
class SpeakEleLoginViewCtr: SpeakEleBaseViewCtr {
// MARK: - ib
@IBOutlet weak var SpeakEmailContentV: UIView!
@IBOutlet weak var SpeakEamil: UITextField!
@IBOutlet weak var SpeakPsContentV: UIView!
@IBOutlet weak var SpeakPs: UITextField!
@IBOutlet weak var SpeakSecure: UIButton!
@IBOutlet weak var SpeakDesc: UILabel!
@IBOutlet var SpeakOtherLogin: [UIButton]!
@IBOutlet weak var SpeakEmailIncorrect: UIView!
@IBOutlet weak var SpeakPsIncorrect: UIView!
private var secureTextEntry:Bool = true {
didSet{
SpeakPs.isSecureTextEntry = secureTextEntry
SpeakSecure.isSelected = !secureTextEntry
}
}
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
SpeakEmailIncorrect.isHidden = true
SpeakPsIncorrect.isHidden = true
secureTextEntry = true
}
override func setup() {
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
SpeakOtherLogin.forEach { button in
button.shadow(cornerRadius: 20, shadowColor: .init(hex: 0x000000,alpha: 0.06), offset: CGSizeMake(0, 4), opacity: 1, radius: 20)
}
}
@IBAction func SpeakForgot(_ sender: Any) {
}
@IBAction func SpeakCreate(_ sender: Any) {
let email = SpeakEamil.text ?? ""
if !email.isValidEmail() {
SpeakEmailIncorrect.isHidden = false
SpeakEmailContentV.borderColor = .init(hex: 0xEB3B2F)
return
}
SpeakEmailIncorrect.isHidden = true
SpeakEmailContentV.borderColor = .clear
let ps = SpeakPs.text ?? ""
if ps.count <= 0 {
SpeakPsIncorrect.isHidden = false
SpeakPsContentV.borderColor = .init(hex: 0xEB3B2F)
return
}
SpeakPsIncorrect.isHidden = true
SpeakPsContentV.borderColor = .clear
} }
@IBAction func SpeakSecureButton(_ sender: UIButton) {
sender.isSelected = !sender.isSelected
secureTextEntry = !sender.isSelected
}
@IBAction func SpeakThreeLoginTaps(_ sender: UIButton) {
if sender == SpeakOtherLogin.last {
let provider = ASAuthorizationAppleIDProvider()
let request = provider.createRequest()
request.requestedScopes = [.fullName, .email]
let controller = ASAuthorizationController(authorizationRequests: [request])
controller.delegate = self
controller.presentationContextProvider = self
controller.performRequests()
}else{
}
}
func toGuide() -> Void {
let guide = SpeakEleGuideViewCtr()
self.navigationController?.pushViewController(guide, animated: true)
}
}
extension SpeakEleLoginViewCtr : ASAuthorizationControllerDelegate , ASAuthorizationControllerPresentationContextProviding {
func authorizationController(controller: ASAuthorizationController,
didCompleteWithAuthorization authorization: ASAuthorization) {
if let appleIDCredential = authorization.credential as? ASAuthorizationAppleIDCredential {
let userIdentifier = appleIDCredential.user
_ = appleIDCredential.fullName
_ = appleIDCredential.email
}
}
func authorizationController(controller: ASAuthorizationController,
didCompleteWithError error: Error) {
print("Apple Login Error: \(error.localizedDescription)")
}
func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor {
return self.view.window!
}
} }
...@@ -7,6 +7,9 @@ ...@@ -7,6 +7,9 @@
import UIKit import UIKit
fileprivate var keyboardKey = SpeakEasyAssociatedKeys.windowkeyboardKey.rawValue
class SpeakKeyboardManager: NSObject { class SpeakKeyboardManager: NSObject {
static let share = SpeakKeyboardManager() static let share = SpeakKeyboardManager()
...@@ -31,25 +34,29 @@ class SpeakKeyboardManager: NSObject { ...@@ -31,25 +34,29 @@ class SpeakKeyboardManager: NSObject {
// MARK: - 键盘处理 // MARK: - 键盘处理
@objc private func keyboardWillShow(_ notification: Notification) { @objc private func keyboardWillShow(_ notification: Notification) {
guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect , guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
let view = notification.object as? UIView else { return } let currentFirstResponder = findFirstResponder(in: window)
let keyboardTop = window.convert(keyboardFrame, from: nil).minY
// let keyboardTop = window.convert(keyboardFrame, from: nil).minY
//
// let textViewBottom = window.convert(bounds, from: superview).maxY
// let overlap = textViewBottom - keyboardTop + 10 // 额外间距
var textviewbottom:CGFloat = 0
let overlap = keyboardFrame.height - window.safeAreaInsets.bottom if let input = currentFirstResponder as? UITextField {
if overlap > 0 { textviewbottom = window.convert(input.bounds, from: input.superview).maxY
var frame = window.frame }else if let input = currentFirstResponder as? UITextView {
frame.origin.y -= overlap textviewbottom = window.convert(input.bounds, from: input.superview).maxY
window.frame = frame }
window.iskeyboradShow = true
if textviewbottom > keyboardTop {
let overlap = (textviewbottom - keyboardTop) + window.safeAreaInsets.bottom
if overlap > 0 {
var frame = window.frame
frame.origin.y -= overlap
window.frame = frame
}
} }
} }
@objc private func keyboardWillHide(_ notification: Notification) { @objc private func keyboardWillHide(_ notification: Notification) {
window.iskeyboradShow = false
window.frame = UIScreen.main.bounds window.frame = UIScreen.main.bounds
} }
...@@ -57,18 +64,42 @@ class SpeakKeyboardManager: NSObject { ...@@ -57,18 +64,42 @@ class SpeakKeyboardManager: NSObject {
private override init() { private override init() {
} }
private func findFirstResponder(in view: UIView?) -> UIResponder? {
guard let view = view else { return nil }
if view.isFirstResponder {
return view
}
for subview in view.subviews {
if let firstResponder = findFirstResponder(in: subview) {
return firstResponder
}
}
return nil
}
} }
extension UIWindow { extension UIWindow {
var iskeyboradShow:Bool {
set {
objc_setAssociatedObject(self, &keyboardKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
}
get {
return objc_getAssociatedObject(self, &keyboardKey) as? Bool ?? false
}
}
open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { open override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
let frame = self.frame let frame = self.frame
if frame.origin.y < 0 { let view = super.hitTest(point, with: event)
if (frame.origin.y < 0 || iskeyboradShow) && !(view is UITextField || view is UITextView) {
self.endEditing(false) self.endEditing(false)
return nil return nil
}else{ }else{
return super.hitTest(point, with: event) return view
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment