adapt view controller size to content size

This commit is contained in:
David Idmansour 2018-06-29 14:12:12 +02:00
parent 421212f2f1
commit afd3d7a880
4 changed files with 35 additions and 22 deletions

View file

@ -1232,7 +1232,7 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut
content.categoryIdentifier = @"msg_cat";
// save data to user info for rich notification content
NSMutableArray *msgs = [NSMutableArray array];
bctbx_list_t *history = linphone_chat_room_get_history(room, 4);
bctbx_list_t *history = linphone_chat_room_get_history(room, 6);
while (history) {
NSMutableDictionary *msgData = [NSMutableDictionary dictionary];
LinphoneChatMessage *msg = history->data;

View file

@ -18,15 +18,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="notificationCell" rowHeight="100" id="4dO-Sq-LtB" customClass="NotificationTableViewCell">
<rect key="frame" x="0.0" y="28" width="375" height="100"/>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="notificationCell" id="4dO-Sq-LtB" customClass="NotificationTableViewCell">
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="4dO-Sq-LtB" id="Q3t-C0-U1O">
<rect key="frame" x="0.0" y="0.0" width="375" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="OXj-8D-5BS">
<rect key="frame" x="60" y="10" width="310" height="88"/>
<rect key="frame" x="60" y="10" width="310" height="32"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="WZa-ow-o0L">
<rect key="frame" x="0.0" y="0.0" width="310" height="17"/>
@ -38,12 +38,12 @@
<nil key="highlightedColor"/>
</label>
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" text="Lorem ipsum " textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="3tK-2u-Ixe">
<rect key="frame" x="0.0" y="17" width="310" height="57.5"/>
<rect key="frame" x="0.0" y="17" width="310" height="1.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
</textView>
<stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="rnc-rL-KN8">
<rect key="frame" x="0.0" y="74.5" width="310" height="13.5"/>
<rect key="frame" x="0.0" y="18.5" width="310" height="13.5"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gv1-l8-gh3">
<rect key="frame" x="0.0" y="0.0" width="292" height="13.5"/>
@ -81,13 +81,13 @@
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" translatesAutoresizingMaskIntoConstraints="NO" id="Wh2-bk-96C" userLabel="BottomBar">
<rect key="frame" x="0.0" y="99" width="375" height="1"/>
<rect key="frame" x="0.0" y="43" width="375" height="1"/>
<constraints>
<constraint firstAttribute="height" constant="1" id="xx0-Om-qom"/>
</constraints>
</imageView>
<imageView userInteractionEnabled="NO" alpha="0.20000000000000001" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" translatesAutoresizingMaskIntoConstraints="NO" id="FHB-G3-atz">
<rect key="frame" x="0.0" y="0.0" width="375" height="100"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
</imageView>
</subviews>
<constraints>

View file

@ -20,6 +20,5 @@
@property float height;
- (CGSize)ViewSizeForMessage:(NSString *)chat withWidth:(int)width;
- (CGSize)ViewHeightForMessage:(NSString *)messageText withWidth:(int)width;
@end

View file

@ -26,20 +26,34 @@
}
- (void)didReceiveNotification:(UNNotification *)notification {
static float initialHeight = -1;
if (initialHeight < 0)
initialHeight = self.tableView.frame.size.height;
printf("Initial height : %f\n", initialHeight);
if (msgs)
[msgs addObject:[((NSArray *)[[[[notification request] content] userInfo] objectForKey:@"msgs"]) lastObject]];
else
msgs = [NSMutableArray arrayWithArray:[[[[notification request] content] userInfo] objectForKey:@"msgs"]];
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:msgs.count - 1
inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
float height = 0;
for (int i = 0 ; i < self->msgs.count ; i++) {
height += [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
}
if (height > initialHeight) {
CGRect frame = self.tableView.frame;
frame.size.height = height;
frame.origin = CGPointMake(0, 0);
self.tableView.frame = frame;
self.tableView.bounds = frame;
self.preferredContentSize = CGSizeMake(self.preferredContentSize.width, height);
}
printf("Height : %f\n", height);
NSLog(@"Content length : %f", self.tableView.contentSize.height);
NSLog(@"Number of rows : %d", (unsigned int)[self tableView:self.tableView numberOfRowsInSection:0]);
[self.view.superview bringSubviewToFront:self.tableView];
NSLog(@"View length : %f", self.tableView.bounds.size.height);
NSLog(@"View bounds length : %f", self.tableView.bounds.size.height);
NSLog(@"View frame length : %f", self.tableView.frame.size.height);
NSLog(@"View bounds y : %f", self.tableView.bounds.origin.y);
NSLog(@"View frame y : %f", self.tableView.frame.origin.y);
}
#pragma mark - UITableViewDataSource Functions
@ -73,10 +87,7 @@
cell.height = size.height;
cell.nameDate.textColor = [UIColor colorWithPatternImage:cell.background.image];
cell.msgText.textColor = [UIColor darkGrayColor];
if (!isOutgoing) {
cell.imdm.hidden = YES;
cell.imdmImage.hidden = YES;
}
cell.imdm.hidden = cell.imdmImage.hidden = !isOutgoing;
if ([imdm isEqualToString:@"LinphoneChatMessageStateDelivered"] || [imdm isEqualToString:@"LinphoneChatMessageStateDeliveredToUser"]) {
cell.imdm.text = NSLocalizedString(@"Delivered", nil);
cell.imdm.textColor = [UIColor grayColor];
@ -93,6 +104,9 @@
cell.imdm.hidden = YES;
printf("Taille label : %f\n", cell.nameDate.font.pointSize);
printf("Taille field : %f\n", cell.msgText.font.pointSize);
printf("%d\n", (unsigned int)indexPath.row);
printf("X : %f\n", cell.frame.origin.x);
printf("Y : %f\n", cell.frame.origin.y);
return cell;
}
@ -103,7 +117,7 @@
cell.msgText = [[UITextView alloc] init];
cell.msgText.text = ((NSString *)[msgs[indexPath.row] objectForKey:@"msg"]);
cell.msgText.font = [UIFont systemFontOfSize:17];
return [cell ViewHeightForMessage:cell.msgText.text withWidth:self.view.bounds.size.width - 10].height + 5;
return [cell ViewSizeForMessage:cell.msgText.text withWidth:self.view.bounds.size.width - 10].height + 5;
}
@end