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;
};
......
//
// 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