Roll camera display like in twitter app?

How would you display photos of users, for example, in the twitter application, where the photo stream is located directly under the keyboard, for example:

enter image description here

enter image description here

enter image description here

+5
source share
4 answers

I solved my question using the RRMessageController component https://github.com/remirobert/RRMessageController

0
source

Add the AssetsLibrary framework

Then write a code similar to:

 @interface ImageCell : UICollectionViewCell @property (strong) UIImageView *imageView; @end @implementation ImageCell - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; self.imageView = [UIImageView new]; [self addSubview:self.imageView]; return self; } - (void)layoutSubviews { [super layoutSubviews]; self.imageView.frame = self.bounds; } @end 

Then:

 #import "ViewController.h" #import <AssetsLibrary/AssetsLibrary.h> @interface ViewController () @property (strong) NSMutableArray *thumbnails; @property (strong) UICollectionView *collectionView; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectInset(self.view.bounds, 20, 20) collectionViewLayout:[UICollectionViewFlowLayout new]]; self.collectionView.backgroundColor = [UIColor clearColor]; [self.collectionView registerClass:[ImageCell class] forCellWithReuseIdentifier:@"Cell"]; self.collectionView.dataSource = self; self.collectionView.delegate = self; [self.view addSubview:self.collectionView]; ALAssetsLibrary *library = [ALAssetsLibrary new]; self.thumbnails = [NSMutableArray new]; __weak ViewController *weakSelf = self; [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:^(ALAssetsGroup *group, BOOL *stop) { [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) { ViewController *strongSelf = weakSelf; if(!result.thumbnail) return; [strongSelf.thumbnails addObject:[UIImage imageWithCGImage:result.thumbnail]]; [strongSelf updateUI]; }]; } failureBlock:^(NSError *error){}]; } - (void)updateUI { [self.collectionView reloadData]; } - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return self.thumbnails.count; } - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath { UIImage *image = self.thumbnails[indexPath.row]; return image.size; } - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { ImageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; cell.imageView.image = self.thumbnails[indexPath.row]; return cell; } @end 

This code needs to be optimized from here depending on the requirements of the application. It is also necessary to customize the frame and layout of the collection to meet the requirements of the user interface.

Screenshot of Result

+1
source
 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init]; imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; [self presentViewController:imagePickerController animated:YES completion:nil]; 
0
source

Here is a class that mimics the same behavior:

enter image description here

You can download it here: Link

0
source

Source: https://habr.com/ru/post/1210439/


All Articles