IMessageAttachment 1.1.23

IMessageAttachment 1.1.23

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Mar 2018

Maintained by Mark Prutskiy.



  • By
  • Mark Prutskiy

A simple iOS photo attachment control with feed of photos from library and camera streaming for capture photo.

IMessageAttachment inspired and copied from iMessage attachment control.
Attachment control from iMessage:
Alt    Alt
IMessageAttachment example:
     Alt    Alt   
IMessageAttachment implementetion in a project:
  Alt    Alt

Works on iOS 8+.

Usage

IMessageAttachment is just a UICollectionView with controls, designed for use with keyboard like in iMessage application. Setup IMessageCollectionView in your viewController, set the delegate (which must conform to IMessageViewControllerDelegate) and implement the 1 required delegate methods to provide UIImage from controls.

See the code snippet below for an example of how to implement the IMessageAttachment control. There is also a simple demo app within the project.

// define IMessageCollectionView
@property (nonatomic, weak) IBOutlet IMessageCollectionView *attachmentCollectionView;
@property (nonatomic, weak) IBOutlet NSLayoutConstraint *attachmentCollectionViewHeightConstraint;

// set delegate in viewDidLoad()
self.attachmentCollectionView.VCDelegate = self;

// define IMessageViewControllerProtocol
- (void)pickedAttachmentImage:(UIImage *)attachmentImage {
    [self.attachmentContent addObject:attachmentImage];
}

You can update attachmentCollectionView's height automatically by take keyboard's height. And it's required thing if you wanna work like iMessage attachment control with keyboard.

// setup notification
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(updateAttachmentHeight:)
                                             name:UIKeyboardDidShowNotification
                                           object:nil];

// update attachmentCollectionView's height
- (void)updateAttachmentHeight:(NSNotification*)notification {
    NSDictionary* keyboardInfo = [notification userInfo];
    NSValue* keyboardFrameBegin = [keyboardInfo valueForKey:UIKeyboardFrameBeginUserInfoKey];
    CGFloat height = [keyboardFrameBegin CGRectValue].size.height;

    self.attachmentCollectionViewHeightConstraint.constant = height;
    [self.attachmentCollectionView updateCollectionViewHeight:height];
}

That's all.

Installation

IMessageAttachment is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "IMessageAttachment"

Or you can copy IMessageAttachment folder to your project.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Then import the IMessageCollectionView into your source files:

#import "IMessageCollectionView.h"

Author

Mark Prutskiy, [email protected] HealthJoy

License

IMessageAttachment is available under the MIT license. See the LICENSE file for more info.