Skip to content

Commit

Permalink
Fixes #7
Browse files Browse the repository at this point in the history
Pass the textview instance in delegate function textViewDidChangeHeight.
  • Loading branch information
KennethTsang committed Mar 12, 2017
1 parent a251d37 commit dcc80bf
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Example/GrowingTextView/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ViewController: UIViewController {
}

extension ViewController: GrowingTextViewDelegate {
func textViewDidChangeHeight(_ height: CGFloat) {
func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat) {
UIView.animate(withDuration: 0.3, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.7, options: [.curveLinear], animations: { () -> Void in
self.inputToolbar.layoutIfNeeded()
}, completion: nil)
Expand Down
2 changes: 1 addition & 1 deletion GrowingTextView.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = "GrowingTextView"
s.version = "0.2.1"
s.version = "0.2.2"
s.summary = "UITextView on Swift3. Support of auto growing, placeholder and length limit."

# This description is used to generate tags and improve search results.
Expand Down
4 changes: 2 additions & 2 deletions Pod/Classes/GrowingTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import UIKit

@objc public protocol GrowingTextViewDelegate: UITextViewDelegate {
@objc optional func textViewDidChangeHeight(_ height: CGFloat)
@objc optional func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat)
}

@objc open class GrowingTextView: UITextView {
Expand Down Expand Up @@ -87,7 +87,7 @@ import UIKit
self.heightConstraint!.constant = height;
scrollRangeToVisible(NSMakeRange(0, 0))
if let delegate = delegate as? GrowingTextViewDelegate {
delegate.textViewDidChangeHeight?(height)
delegate.textViewDidChangeHeight!(self, height: height)
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Adopt `GrowingTextViewDelegate` instead of UITextViewDelegate, and listen to hei

```swift
class ViewController: UIViewController, GrowingTextViewDelegate {
func textViewDidChangeHeight(_ height: CGFloat) {
func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat) {
...
}
}
Expand All @@ -95,7 +95,7 @@ To animate the height change, adopt `GrowingTextViewDelegate` instead of UITextV

```swift
class ViewController: UIViewController, GrowingTextViewDelegate {
func textViewDidChangeHeight(_ height: CGFloat) {
func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat) {
UIView.animate(withDuration: 0.2) {
self.textView.layoutIfNeeded()
}
Expand All @@ -107,7 +107,7 @@ In some cases, you may also need to animate it's superview, e.g. toolbar.

```swift
class ViewController: UIViewController, GrowingTextViewDelegate {
func textViewDidChangeHeight(_ height: CGFloat) {
func textViewDidChangeHeight(_ textView: GrowingTextView, height: CGFloat) {
UIView.animate(withDuration: 0.2) {
self.myToolbar.layoutIfNeeded()
}
Expand Down

0 comments on commit dcc80bf

Please sign in to comment.