Skip to content

Commit

Permalink
updating to swift 4 and fixing orientation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorJera committed Nov 21, 2017
1 parent a2ab71c commit d5fa581
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Example/Malert.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
58EB663D3F8BC672F363158F /* [CP] Copy Pods Resources */ = {
Expand Down Expand Up @@ -385,7 +385,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
9F1A9335C3FCF99282245E90 /* [CP] Embed Pods Frameworks */ = {
Expand Down
1 change: 1 addition & 0 deletions Example/Malert/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
5 changes: 3 additions & 2 deletions Example/Malert/view/FirstCustomView.xib
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="12118" systemVersion="16A323" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12086"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ DEPENDENCIES:

EXTERNAL SOURCES:
Malert:
:path: "../"
:path: ../

SPEC CHECKSUMS:
Cartography: d295eb25ab54bb57eecd8c2f04e9648c850f1281
Malert: 1b2ee363459649a97812e011ab918e05d283036c

PODFILE CHECKSUM: 74b915e073dcad13b9ddf42484d1b22ace7e65e4

COCOAPODS: 1.2.1
COCOAPODS: 1.3.1
51 changes: 31 additions & 20 deletions Malert/Classes/ViewController/MalertViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ protocol MalertViewControllerCallback: class {
}

class MalertViewController: BaseMalertViewController {

fileprivate lazy var visibleView: UIView = self.buildVisibleView()

fileprivate weak var callback: MalertViewControllerCallback?
fileprivate var tapToDismiss: Bool = false
fileprivate let bottomInsetConstraintGroup = ConstraintGroup()

fileprivate let visibleViewConstraintGroup = ConstraintGroup()

fileprivate let malertConstraintGroup = ConstraintGroup()

fileprivate var malertView: MalertView? {
Expand All @@ -34,17 +36,12 @@ class MalertViewController: BaseMalertViewController {
}
malertView.alpha = 1
visibleView.addSubview(malertView)
constrain(malertView, visibleView, replace: malertConstraintGroup) { (malert, container) in
malert.center == container.center
malert.left == container.left + 16
malert.right == container.right - 16
}
self.viewDidLayoutSubviews()
}
}

override func loadView() {
super.loadView()
view = UIView(frame: UIScreen.main.bounds)
view.backgroundColor = UIColor(white: 0, alpha: 0.4)
}

Expand All @@ -57,22 +54,41 @@ class MalertViewController: BaseMalertViewController {
listenKeyboard()
}

override func updateViewConstraints() {
super.updateViewConstraints()
constrain(view, visibleView, replace: bottomInsetConstraintGroup, block: { (view, visibleView) -> () in
visibleView.bottom == view.bottom - keyboardRect.size.height
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

constrain(view, visibleView, replace: visibleViewConstraintGroup, block: {[weak self] (view, visibleView) -> () in
guard let strongSelf = self else { return }
visibleView.top == view.top
visibleView.right == view.right
visibleView.left == view.left
visibleView.bottom == view.bottom - strongSelf.keyboardRect.size.height
})

if let malertView = malertView {

constrain(malertView, visibleView, replace: malertConstraintGroup) { (malert, container) in
malert.center == container.center
malert.left == container.left + 16
malert.right == container.right - 16

if UIDevice.current.orientation.isLandscape {
malert.top >= container.top + 16 ~ UILayoutPriority(900)
malert.bottom >= container.bottom - 16 ~ UILayoutPriority(900)
}
}
}
}

override func keyboardWillShow(sender: NSNotification) {
super.keyboardWillShow(sender: sender)
view.setNeedsUpdateConstraints()
self.viewDidLayoutSubviews()
view.layoutIfNeeded()
}

override func keyboardWillHide(sender: NSNotification) {
super.keyboardWillHide(sender: sender)
view.setNeedsUpdateConstraints()
self.viewDidLayoutSubviews()
view.layoutIfNeeded()
}

Expand Down Expand Up @@ -108,13 +124,8 @@ extension MalertViewController {
}

func buildVisibleView() -> UIView {
let visibleView = UIView(frame: self.view.frame)
let visibleView = UIView()
view.addSubview(visibleView)
constrain(visibleView, view) { (visibleView, containerView) in
visibleView.top == containerView.top
visibleView.right == containerView.right
visibleView.left == containerView.left
}
return visibleView
}
}

0 comments on commit d5fa581

Please sign in to comment.