diff --git a/iOS/sosmessage/sosmessage/NSString+SOSMessage.m b/iOS/sosmessage/sosmessage/NSString+SOSMessage.m
index c6e6424..d35571d 100644
--- a/iOS/sosmessage/sosmessage/NSString+SOSMessage.m
+++ b/iOS/sosmessage/sosmessage/NSString+SOSMessage.m
@@ -19,9 +19,9 @@ -(float)sizeForBlocksForView:(UIView*)view {
-(float)blocksCount:(UIView*)view {
float widthWithFont = [self sizeWithFont:SOSFONT].width;
- NSLog(@"Width with font for %@ : %.2f", self, widthWithFont);
+ //NSLog(@"Width with font for %@ : %.2f", self, widthWithFont);
float blockSize = view.bounds.size.width / NB_BLOCKS;
- NSLog(@"Frame width: %.2f and a block: %.2f", view.frame.size.width, blockSize);
+ //NSLog(@"Frame width: %.2f and a block: %.2f", view.frame.size.width, blockSize);
return ceilf(widthWithFont / blockSize);
}
diff --git a/iOS/sosmessage/sosmessage/ViewController.h b/iOS/sosmessage/sosmessage/ViewController.h
index 2343a48..474bbc8 100644
--- a/iOS/sosmessage/sosmessage/ViewController.h
+++ b/iOS/sosmessage/sosmessage/ViewController.h
@@ -29,6 +29,7 @@
- (void)addSOSCategory:(NSString*)label inPosX:(int)posX andPosY:(int)posY;
- (void)fillEmptyBlocks:(int)nb fromPosX:(int)posX andPosY:(int)posY;
+- (void)refreshCategoriesWithNotification:(NSNotification*)notification;
- (void)refreshCategories;
- (void)removeCategoriesLabel;
- (void)handleCategoryTapping:(UIGestureRecognizer *)sender;
diff --git a/iOS/sosmessage/sosmessage/ViewController.m b/iOS/sosmessage/sosmessage/ViewController.m
index 0bc5cd8..45a90d4 100644
--- a/iOS/sosmessage/sosmessage/ViewController.m
+++ b/iOS/sosmessage/sosmessage/ViewController.m
@@ -45,7 +45,8 @@ - (void)viewWillAppear:(BOOL)animated
labels = [[NSMutableArray alloc] initWithObjects:@"Remerciements", @"Calques", nil];
[super viewWillAppear:animated];
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshCategories) name:UIDeviceOrientationDidChangeNotification object:nil];
+ [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(refreshCategoriesWithNotification:) name:UIDeviceOrientationDidChangeNotification object:nil];
[self refreshCategories];
}
@@ -57,6 +58,7 @@ - (void)viewDidAppear:(BOOL)animated
- (void)viewWillDisappear:(BOOL)animated
{
+ [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[labels release];
@@ -73,14 +75,6 @@ - (void)viewDidDisappear:(BOOL)animated
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
-
- /*
- // Return YES for supported orientations
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
- return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
- } else {
- return YES;
- }*/
}
-(BOOL)canBecomeFirstResponder {
@@ -130,7 +124,7 @@ - (void)addSOSCategory:(NSString*)label inPosX:(int)posX andPosY:(int)posY {
float rectWidth = ceilf([label sizeForBlocksForView:self.view]);
float rectHeight = 1; //arbitrary set to 1
- NSLog(@"Place label (%@) at (%.2f;%.2f) with size (%.2f;%.2f)", label, rectX, rectY, rectWidth, rectHeight);
+ //NSLog(@"Place label (%@) at (%.2f;%.2f) with size (%.2f;%.2f)", label, rectX, rectY, rectWidth, rectHeight);
UILabel* uiLabel = [[[UILabel alloc] initWithFrame:CGRectMake(rectX, posY, rectWidth, rectHeight)] autorelease];
uiLabel.backgroundColor = [UIColor colorWithHue:label.hue saturation:0.4 brightness:0.9 alpha:1.0];
@@ -148,13 +142,14 @@ - (void)addSOSCategory:(NSString*)label inPosX:(int)posX andPosY:(int)posY {
- (void)fillEmptyBlocks:(int)nb fromPosX:(int)posX andPosY:(int)posY {
float blockSize = self.view.bounds.size.width / NB_BLOCKS;
+ NSLog(@"Bounds width: %.2f and Frame width: %.2f", self.view.bounds.size.width, self.view.frame.size.width);
float rectX = floorf(blockSize * posX);
float rectY = posY; //origin y will be re-calculate after views are generated
float rectWidth = blockSize * nb;
float rectHeight = 1; //arbitrary set to 1
- NSLog(@"Fill %d blocks at (%.2f;%.2f) with size (%.2f;%.2f)", nb, rectX, rectY, rectWidth, rectHeight);
+ //NSLog(@"Fill %d blocks at (%.2f;%.2f) with size (%.2f;%.2f)", nb, rectX, rectY, rectWidth, rectHeight);
UILabel* emptyBlocks = [[[UILabel alloc] initWithFrame:CGRectMake(rectX, posY, rectWidth, rectHeight)] autorelease];
float hue = (rand()%24) / 24.0;
@@ -163,6 +158,10 @@ - (void)fillEmptyBlocks:(int)nb fromPosX:(int)posX andPosY:(int)posY {
[self.view addSubview:emptyBlocks];
}
+- (void)refreshCategoriesWithNotification:(NSNotification*)notification {
+ [self refreshCategories];
+}
+
- (void)refreshCategories {
[self removeCategoriesLabel];
@@ -198,7 +197,7 @@ - (void)refreshCategories {
if (x == 0) {
y -= 1;
}
- float fitHeight = self.view.bounds.size.height / y;
+ float fitHeight = self.view.bounds.size.height / (y + 1);
for (UIView* subView in self.view.subviews) {
if ([subView isKindOfClass:[UILabel class]] && subView.tag == 0) {
subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y * fitHeight, subView.frame.size.width, fitHeight);
@@ -207,13 +206,11 @@ - (void)refreshCategories {
}
-(void)removeCategoriesLabel {
- NSLog(@"Nb of subViews: %d", self.view.subviews.count);
for (UIView* subView in self.view.subviews) {
if ([subView isKindOfClass:[UILabel class]] && subView.tag == 0) {
[subView removeFromSuperview];
}
}
- NSLog(@"Nb of subViews after remove: %d", self.view.subviews.count);
}
- (void)handleCategoryTapping:(UIGestureRecognizer *)sender {
diff --git a/iOS/sosmessage/sosmessage/sosmessage-Info.plist b/iOS/sosmessage/sosmessage/sosmessage-Info.plist
index 7e70057..eead0d2 100644
--- a/iOS/sosmessage/sosmessage/sosmessage-Info.plist
+++ b/iOS/sosmessage/sosmessage/sosmessage-Info.plist
@@ -35,6 +35,7 @@
UIInterfaceOrientationPortrait
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
+ UIInterfaceOrientationPortraitUpsideDown
UISupportedInterfaceOrientations~ipad