From c616ef19178c15feec506cdac7eb473e4b8d2f81 Mon Sep 17 00:00:00 2001 From: kenneth Date: Thu, 8 Dec 2016 12:15:07 +0800 Subject: [PATCH 1/3] add iOS 8 support add iOS version check --- TinyConsole/TinyConsoleController.swift | 48 +++++++++++++++------ TinyConsole/TinyConsoleViewController.swift | 15 +++++-- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/TinyConsole/TinyConsoleController.swift b/TinyConsole/TinyConsoleController.swift index 8696b3e..e81d27d 100644 --- a/TinyConsole/TinyConsoleController.swift +++ b/TinyConsole/TinyConsoleController.swift @@ -59,23 +59,43 @@ open class TinyConsoleController: UIViewController { } lazy var consoleViewHeightConstraint: NSLayoutConstraint? = { - return self.consoleViewController.view.heightAnchor.constraint(equalToConstant: 0) + if #available(iOS 9, *) { + return self.consoleViewController.view.heightAnchor.constraint(equalToConstant: 0) + } else { + return NSLayoutConstraint(item: self.consoleViewController.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 0) + } }() func setupConstraints() { - self.rootViewController?.view.translatesAutoresizingMaskIntoConstraints = false - self.rootViewController?.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true - self.rootViewController?.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true - self.rootViewController?.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true - - self.consoleViewController.view.translatesAutoresizingMaskIntoConstraints = false - self.consoleViewController.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true - self.consoleViewController.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true - self.consoleViewController.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true - - self.consoleViewHeightConstraint?.isActive = true - - self.rootViewController?.view.bottomAnchor.constraint(equalTo: self.consoleViewController.view.topAnchor).isActive = true + if #available(iOS 9, *) { + self.rootViewController?.view.translatesAutoresizingMaskIntoConstraints = false + self.rootViewController?.view.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true + self.rootViewController?.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true + self.rootViewController?.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true + + self.consoleViewController.view.translatesAutoresizingMaskIntoConstraints = false + self.consoleViewController.view.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true + self.consoleViewController.view.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true + self.consoleViewController.view.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true + + self.consoleViewHeightConstraint?.isActive = true + + self.rootViewController?.view.bottomAnchor.constraint(equalTo: self.consoleViewController.view.topAnchor).isActive = true + } else { + self.rootViewController?.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true + + self.consoleViewController.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint(item: self.consoleViewController.view, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: self.consoleViewController.view, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: self.consoleViewController.view, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true + + self.consoleViewHeightConstraint?.isActive = true + + NSLayoutConstraint(item: (self.rootViewController?.view)!, attribute: .bottom, relatedBy: .equal, toItem: self.consoleViewController.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true + } } open override func updateViewConstraints() { diff --git a/TinyConsole/TinyConsoleViewController.swift b/TinyConsole/TinyConsoleViewController.swift index 04f553e..a0d70df 100644 --- a/TinyConsole/TinyConsoleViewController.swift +++ b/TinyConsole/TinyConsoleViewController.swift @@ -40,10 +40,17 @@ class TinyConsoleViewController: UIViewController { func setupConstraints() { self.consoleTextView.translatesAutoresizingMaskIntoConstraints = false - self.consoleTextView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true - self.consoleTextView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true - self.consoleTextView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true - self.consoleTextView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true + if #available(iOS 9, *) { + self.consoleTextView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true + self.consoleTextView.leftAnchor.constraint(equalTo: self.view.leftAnchor).isActive = true + self.consoleTextView.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true + self.consoleTextView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true + } else { + NSLayoutConstraint(item: self.consoleTextView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: self.consoleTextView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: self.consoleTextView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0).isActive = true + NSLayoutConstraint(item: self.consoleTextView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true + } } func customText(sender: UITapGestureRecognizer) { From 4ae7ebbc9601a90a92950246ef8dc92ffd4c2e10 Mon Sep 17 00:00:00 2001 From: kenneth Date: Fri, 9 Dec 2016 15:42:03 +0800 Subject: [PATCH 2/3] fix the two-fingers-tap gesture bug on iOS 8 the two-fingers-tap gesture on the viewcontroller is blocked by the gesture on the textview --- TinyConsole/TinyConsoleViewController.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TinyConsole/TinyConsoleViewController.swift b/TinyConsole/TinyConsoleViewController.swift index a0d70df..ce1bc25 100644 --- a/TinyConsole/TinyConsoleViewController.swift +++ b/TinyConsole/TinyConsoleViewController.swift @@ -29,7 +29,11 @@ class TinyConsoleViewController: UIViewController { let addCustomTextGesture = UITapGestureRecognizer(target: self, action: #selector(customText)) addCustomTextGesture.numberOfTouchesRequired = 2 - self.view.addGestureRecognizer(addCustomTextGesture) + if #available(iOS 9, *) { + self.view.addGestureRecognizer(addCustomTextGesture) + } else { + self.consoleTextView.addGestureRecognizer(addCustomTextGesture) + } let showAdditionalActionsGesture = UITapGestureRecognizer(target: self, action: #selector(additionalActions)) showAdditionalActionsGesture.numberOfTouchesRequired = 3 From 33f799d1afdee81f67282138926d7433b2cf2ea6 Mon Sep 17 00:00:00 2001 From: kenneth Date: Sun, 11 Dec 2016 16:23:31 +0800 Subject: [PATCH 3/3] change the deployment target to iOS 8 --- TinyConsole.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TinyConsole.xcodeproj/project.pbxproj b/TinyConsole.xcodeproj/project.pbxproj index bb4345f..2c67ddf 100644 --- a/TinyConsole.xcodeproj/project.pbxproj +++ b/TinyConsole.xcodeproj/project.pbxproj @@ -339,7 +339,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "$(SRCROOT)/TinyConsole/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -399,7 +399,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "$(SRCROOT)/TinyConsole/Supporting Files/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = com.devranuenal.TinyConsole; @@ -459,7 +459,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "TinyConsole-Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -511,7 +511,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "TinyConsole-Example/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.devranuenal.TinyConsole-Example";