Skip to content

Commit

Permalink
Merge pull request #5 from wangguangfeng/master
Browse files Browse the repository at this point in the history
add iOS 8 support
  • Loading branch information
Cosmo committed Dec 11, 2016
2 parents af015c6 + 33f799d commit cbc5cfd
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 23 deletions.
8 changes: 4 additions & 4 deletions TinyConsole.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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";
Expand Down
48 changes: 34 additions & 14 deletions TinyConsole/TinyConsoleController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 16 additions & 5 deletions TinyConsole/TinyConsoleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,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
Expand All @@ -38,10 +42,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) {
Expand Down

0 comments on commit cbc5cfd

Please sign in to comment.