Commit f22d7bdb by Daniel Dahan

Merge pull request #302 from ramonvic/development

Fixed TextField Crash when dealoc itself
parents bc0d00c7 71482c7e
......@@ -12,6 +12,9 @@
96D528071C8198AD00D3BDD1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D528051C8198AD00D3BDD1 /* Main.storyboard */; };
96D528091C8198AD00D3BDD1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96D528081C8198AD00D3BDD1 /* Assets.xcassets */; };
96D5280C1C8198AD00D3BDD1 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */; };
F602C1681CBDEEB8003DFE27 /* Material.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F602C1671CBDEEB8003DFE27 /* Material.framework */; };
F602C1691CBDEEB8003DFE27 /* Material.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = F602C1671CBDEEB8003DFE27 /* Material.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
F602C16B1CBDEEE4003DFE27 /* ViewController2.swift in Sources */ = {isa = PBXBuildFile; fileRef = F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -21,6 +24,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
F602C1691CBDEEB8003DFE27 /* Material.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
......@@ -35,6 +39,9 @@
96D528081C8198AD00D3BDD1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
96D5280B1C8198AD00D3BDD1 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
96D5280D1C8198AD00D3BDD1 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
F602C1651CBDEE85003DFE27 /* Material.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Material.framework; path = "../../../build/Debug-iphoneos/Material.framework"; sourceTree = "<group>"; };
F602C1671CBDEEB8003DFE27 /* Material.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = Material.framework; path = "/Users/ramon/Library/Developer/Xcode/DerivedData/Material-himrdtrjxqulxbgtyvxqqgkjdthx/Build/Products/Debug-iphonesimulator/Material.framework"; sourceTree = "<absolute>"; };
F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController2.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -42,6 +49,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
F602C1681CBDEEB8003DFE27 /* Material.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......@@ -51,6 +59,8 @@
96D527F51C8198AD00D3BDD1 = {
isa = PBXGroup;
children = (
F602C1671CBDEEB8003DFE27 /* Material.framework */,
F602C1651CBDEE85003DFE27 /* Material.framework */,
96D528001C8198AD00D3BDD1 /* TextField */,
96D527FF1C8198AD00D3BDD1 /* Products */,
);
......@@ -73,6 +83,7 @@
96D528081C8198AD00D3BDD1 /* Assets.xcassets */,
96D5280A1C8198AD00D3BDD1 /* LaunchScreen.storyboard */,
96D5280D1C8198AD00D3BDD1 /* Info.plist */,
F602C16A1CBDEEE4003DFE27 /* ViewController2.swift */,
);
path = TextField;
sourceTree = "<group>";
......@@ -151,6 +162,7 @@
files = (
96D528041C8198AD00D3BDD1 /* ViewController.swift in Sources */,
96D528021C8198AD00D3BDD1 /* AppDelegate.swift in Sources */,
F602C16B1CBDEEE4003DFE27 /* ViewController2.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
</dependencies>
<scenes>
<!--View Controller-->
......@@ -17,21 +18,42 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3zW-lR-Siu" customClass="TextField" customModule="Material">
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="3zW-lR-Siu" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="41" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="p7i-Yj-Kl0"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fUS-ww-GD9" customClass="TextField" customModule="Material">
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="fUS-ww-GD9" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="157" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="x7c-Zw-Abd"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ROk-Om-Aix">
<rect key="frame" x="277" y="285" width="46" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="g5u-eh-klu"/>
<constraint firstAttribute="width" constant="46" id="pEY-9N-KAi"/>
</constraints>
<state key="normal" title="Open"/>
<connections>
<segue destination="bnT-id-zXl" kind="show" id="SQ4-R4-FyL"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="3zW-lR-Siu" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" constant="21" id="4lG-n9-phz"/>
<constraint firstItem="fUS-ww-GD9" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="NRT-ra-UCs"/>
<constraint firstItem="3zW-lR-Siu" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="Xbp-rO-2qd"/>
<constraint firstItem="ROk-Om-Aix" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="iMc-Rh-hn6"/>
<constraint firstItem="ROk-Om-Aix" firstAttribute="top" secondItem="fUS-ww-GD9" secondAttribute="bottom" constant="98" id="qM7-sR-btl"/>
<constraint firstItem="fUS-ww-GD9" firstAttribute="top" secondItem="3zW-lR-Siu" secondAttribute="bottom" constant="86" id="ueA-T8-0vM"/>
</constraints>
</view>
<connections>
......@@ -42,5 +64,64 @@
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
<!--View Controller2-->
<scene sceneID="crp-rI-egd">
<objects>
<viewController id="bnT-id-zXl" customClass="ViewController2" customModule="TextField" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="xWq-9m-5dl"/>
<viewControllerLayoutGuide type="bottom" id="JCe-cw-Htq"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="s6w-a0-kH1">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Eeh-Ol-bZG" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="63" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="27N-Rl-xug"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="YjB-bn-zu7" customClass="TextField" customModule="Material">
<rect key="frame" x="200" y="179" width="200" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="200" id="dtc-xl-jHa"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="fqE-3b-mxt">
<rect key="frame" x="534" y="28" width="46" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="46" id="ukl-j3-utm"/>
<constraint firstAttribute="height" constant="30" id="zSF-no-ylx"/>
</constraints>
<state key="normal" title="Close"/>
<connections>
<action selector="close:" destination="bnT-id-zXl" eventType="touchUpInside" id="lYs-c9-ZoD"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="YjB-bn-zu7" firstAttribute="centerX" secondItem="s6w-a0-kH1" secondAttribute="centerX" id="0qi-DP-6HZ"/>
<constraint firstItem="fqE-3b-mxt" firstAttribute="top" secondItem="xWq-9m-5dl" secondAttribute="bottom" constant="8" id="7T2-D0-0n4"/>
<constraint firstAttribute="trailingMargin" secondItem="fqE-3b-mxt" secondAttribute="trailing" id="K75-oB-FHc"/>
<constraint firstItem="YjB-bn-zu7" firstAttribute="top" secondItem="Eeh-Ol-bZG" secondAttribute="bottom" constant="86" id="VJX-9a-FzT"/>
<constraint firstItem="Eeh-Ol-bZG" firstAttribute="centerX" secondItem="s6w-a0-kH1" secondAttribute="centerX" id="aHo-N6-p4D"/>
<constraint firstItem="Eeh-Ol-bZG" firstAttribute="top" secondItem="xWq-9m-5dl" secondAttribute="bottom" constant="43" id="h39-tb-Paq"/>
</constraints>
</view>
<connections>
<outlet property="emailField" destination="YjB-bn-zu7" id="0Aj-Dj-nEi"/>
<outlet property="nameField" destination="Eeh-Ol-bZG" id="PQN-kr-OvB"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="1Ho-Zx-Ti5" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1011" y="353"/>
</scene>
</scenes>
</document>
//
// ViewController2.swift
// TextField
//
// Created by Ramon Vicente on 4/13/16.
// Copyright © 2016 CosmicMind, Inc. All rights reserved.
//
import UIKit
import Material
class ViewController2: UIViewController, TextFieldDelegate {
@IBOutlet weak var nameField: TextField!
@IBOutlet weak var emailField: TextField!
@IBAction func close(sender: UIButton) {
dismissViewControllerAnimated(true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
prepareView()
prepareNameField()
prepareEmailField()
}
/// General preparation statements.
private func prepareView() {
view.backgroundColor = MaterialColor.white
}
/// Prepares the name TextField.
private func prepareNameField() {
nameField.placeholder = "First Name"
}
/// Prepares the email TextField.
private func prepareEmailField() {
emailField.delegate = self
emailField.placeholder = "Email"
/*
Used to display the error message, which is displayed when
the user presses the 'return' key.
*/
emailField.detailLabel = UILabel()
emailField.detailLabel!.text = "Email is incorrect."
emailField.detailLabel!.font = RobotoFont.regularWithSize(12)
emailField.detailLabelActiveColor = MaterialColor.red.accent3
// emailField.detailLabelAutoHideEnabled = false // Uncomment this line to have manual hiding.
}
/// Executed when the 'return' key is pressed when using the emailField.
func textFieldShouldReturn(textField: UITextField) -> Bool {
(textField as! TextField).detailLabelHidden = 0 == textField.text?.utf16.count
return false
}
}
\ No newline at end of file
......@@ -631,22 +631,28 @@ public class TextField : UITextField {
titleLabel.frame = bounds
titleLabel.font = font
titleLabel.hidden = false
UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.alpha = 1
self.titleLabel.transform = CGAffineTransformScale(self.titleLabel.transform, 0.75, 0.75)
self.titleLabel.frame = CGRectMake(0, -(self.titleLabelAnimationDistance + h), self.bounds.width, h)
UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self {
self!.titleLabel.alpha = 1
self!.titleLabel.transform = CGAffineTransformScale(self!.titleLabel.transform, 0.75, 0.75)
self!.titleLabel.frame = CGRectMake(0, -(self!.titleLabelAnimationDistance + h), self!.bounds.width, h)
}
})
}
}
/// Hides and animates the titleLabel property.
private func hideTitleLabel() {
UIView.animateWithDuration(0.15, animations: { [unowned self] in
self.titleLabel.transform = CGAffineTransformIdentity
self.titleLabel.frame = self.bounds
}) { [unowned self] _ in
self.placeholder = self.placeholderText
self.titleLabel.hidden = true
UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self {
self!.titleLabel.transform = CGAffineTransformIdentity
self!.titleLabel.frame = self!.bounds
}
}) { [weak self] _ in
if nil != self {
self!.placeholder = self!.placeholderText
self!.titleLabel.hidden = true
}
}
}
......@@ -657,9 +663,11 @@ public class TextField : UITextField {
let h: CGFloat = ceil(v.font.lineHeight)
v.frame = CGRectMake(0, bounds.height + lineLayerDistance, bounds.width, h)
v.hidden = false
UIView.animateWithDuration(0.15, animations: { [unowned self] in
v.frame.origin.y = self.frame.height + self.lineLayerDistance + self.detailLabelAnimationDistance
v.alpha = 1
UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self {
v.frame.origin.y = self!.frame.height + self!.lineLayerDistance + self!.detailLabelAnimationDistance
v.alpha = 1
}
})
}
}
......@@ -668,9 +676,11 @@ public class TextField : UITextField {
/// Hides and animates the detailLabel property.
private func hideDetailLabel() {
if let v: UILabel = detailLabel {
UIView.animateWithDuration(0.15, animations: { [unowned self] in
v.alpha = 0
v.frame.origin.y -= self.detailLabelAnimationDistance
UIView.animateWithDuration(0.15, animations: { [weak self] in
if nil != self {
v.alpha = 0
v.frame.origin.y -= self!.detailLabelAnimationDistance
}
}) { _ in
v.hidden = true
}
......
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