Giter Site home page Giter Site logo

messagecomposerview's Introduction

MessageComposerView

If you find yourself needing a UITextView that sticks to the keyboard similar to an inputAccessoryView that does not disappear when the keyboard hides, you'll quickly find that you'll likely have to build out a fairly time consuming custom view. MessageComposerView aims to save you all that setup time and headache and provide a simple, customizable implementation.

Rather that being an inputAccessoryView, it is a custom UIView that will automatically "stick" the keyboard, handling rotation, text changes and keyboard state changes.

Usage

####Setup In your header file:

  1. Import the MessageComosposerView.h file
  2. Add the MessageComposerViewDelegate delegate
  3. Optionally create a MessageComposerView property for your message composer view.

Example:

#import "MessageComposerView.h"
@interface ViewController : UIViewController<MessageComposerViewDelegate>
@property (nonatomic, strong) MessageComposerView *messageComposerView;
@end

In your class file, instantiate and add MessageComposerView to the bottom of your view controller. You can do this automatically via loadNibNamed:

self.messageComposerView = [[NSBundle mainBundle] loadNibNamed:@"MessageComposerView" owner:nil options:nil][0];
self.messageComposerView.delegate = self;
[self.view addSubview:self.messageComposerView];

Or manually via initWithFrame:

// standard size is (320, 54) but a custom size will also be respected
float defaultWidth  = 320;
float defaultHeight = 54;
CGRect subviewFrame = CGRectMake(0, self.view.frame.size.height-defaultHeight, defaultWidth, defaultHeight);
self.messageComposerView = [[MessageComposerView alloc] initWithFrame:subviewFrame];
[self.view addSubview:self.messageComposerView];

####Delegation The MessageComposerViewDelegate has several delegate methods:

  1. - (void)messageComposerSendMessageClickedWithMessage:(NSString*)message;
    Required - Triggered whenever the user presses the send button. message is the text within the UITextView at the time the button was pressed.

  2. - (void)messageComposerFrameDidChange:(CGRect)frame withAnimationDuration:(float)duration;
    Optional - Triggered whenever the UITextView frame is reconfigured. frame is the CGRect that was applied to the MessageComposerView container.

  3. - (void)messageComposerUserTyping;
    Optional - Triggered whenever the UITextView text changes.

How it works

MessageComposerView tries to avoid hooking into UIKeyboardWillShowNotification and UIKeyboardDidShowNotification as I found them to be at times excessive and difficult to properly manipulate, especially when it came to rotation. Instead the UIKeyboardWillShowNotification notification is used solely to dynamically determine the keyboard animation duration on your device before any animations occur.

The actual resizing of the views is handled via layoutSubviews and through the following UITextViewDelegate methods:

  • - (void)textViewDidBeginEditing:(UITextView*)textView
  • - (void)textViewDidEndEditing:(UITextView*)textView

Contact

If you need to contact me you can do so via my twitter @alexgophermix or through my website thegameengine.org

messagecomposerview's People

Contributors

oseparovic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.