-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMessagesViewController.m
125 lines (89 loc) · 4.43 KB
/
MessagesViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//
// MessagesViewController.m
// MessagesExtension
//
// Created by Rainbow on 10/20/16.
// Copyright © 2016 apple. All rights reserved.
//
#import "MessagesViewController.h"
#import "CollectionViewCell.h"
@interface MessagesViewController() {
NSArray* stickerArray;
int categoryInt;
}
@end
@implementation MessagesViewController
- (void)viewDidLoad {
[super viewDidLoad];
//get the total Pictures
NSString* path = [[NSBundle mainBundle] pathForResource:@"utilitylist" ofType:@"plist"];
NSArray* array = [[NSArray alloc] initWithContentsOfFile:path];
stickerArray = [array valueForKey:@"Pictures"];
// Do any additional setup after loading the view.
}
#pragma mark -
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
NSArray * stickers = [stickerArray objectAtIndex:categoryInt];
return stickers.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"Cell";
CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSArray* pictures = [stickerArray objectAtIndex:categoryInt];
NSURL *urlForSticker = [[NSBundle mainBundle] URLForResource:[pictures objectAtIndex:indexPath.row] withExtension:@"png"];
cell.stickerView.sticker = [[MSSticker alloc] initWithContentsOfFileURL:urlForSticker localizedDescription:@"" error:nil];
return cell;
}
#pragma mark -
#pragma mark - UICollectionViewFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat picDimension = self.view.frame.size.width / 4.0f;
return CGSizeMake(picDimension, picDimension);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
CGFloat leftRightInset = self.view.frame.size.width / 14.0f;
return UIEdgeInsetsMake(0, leftRightInset, 0, leftRightInset);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Conversation Handling
-(void)didBecomeActiveWithConversation:(MSConversation *)conversation {
// Called when the extension is about to move from the inactive to active state.
// This will happen when the extension is about to present UI.
// Use this method to configure the extension and restore previously stored state.
}
-(void)willResignActiveWithConversation:(MSConversation *)conversation {
// Called when the extension is about to move from the active to inactive state.
// This will happen when the user dissmises the extension, changes to a different
// conversation or quits Messages.
// Use this method to release shared resources, save user data, invalidate timers,
// and store enough state information to restore your extension to its current state
// in case it is terminated later.
}
-(void)didReceiveMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
// Called when a message arrives that was generated by another instance of this
// extension on a remote device.
// Use this method to trigger UI updates in response to the message.
}
-(void)didStartSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
// Called when the user taps the send button.
}
-(void)didCancelSendingMessage:(MSMessage *)message conversation:(MSConversation *)conversation {
// Called when the user deletes the message without sending it.
// Use this to clean up state related to the deleted message.
}
-(void)willTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle {
// Called before the extension transitions to a new presentation style.
// Use this method to prepare for the change in presentation style.
}
-(void)didTransitionToPresentationStyle:(MSMessagesAppPresentationStyle)presentationStyle {
[self.collectionView reloadData];
// Called after the extension transitions to a new presentation style.
// Use this method to finalize any behaviors associated with the change in presentation style.
}
@end