2525#define GROUPS_SECTION 0
2626#define ENTRIES_SECTION 1
2727
28+ #define PORTRAIT_BUTTON_WIDTH ([[UIDevice currentDevice ] userInterfaceIdiom ] == UIUserInterfaceIdiomPhone ? 97 .0f : 244 .0f )
29+ #define LANDSCAPE_BUTTON_WIDTH ([[UIDevice currentDevice ] userInterfaceIdiom ] == UIUserInterfaceIdiomPhone ? 186 .0f : 330 .0f )
30+
2831#define SORTED_INSERTION_FAILED NSUIntegerMax
2932
3033@interface GroupViewController ()
@@ -42,6 +45,7 @@ - (NSUInteger)updatePositionOfObject:object inArray:array;
4245@property (nonatomic , copy ) NSString *moveButtonTitle;
4346@property (nonatomic , retain ) UIBarButtonItem *renameButton;
4447@property (nonatomic , copy ) NSString *renameButtonTitle;
48+ @property (nonatomic , assign ) CGFloat currentButtonWidth;
4549
4650@end
4751
@@ -156,6 +160,13 @@ - (void)viewWillAppear:(BOOL)animated {
156160 }
157161
158162 searchDisplayController.searchBar .placeholder = [NSString stringWithFormat: @" %@ %@ " , NSLocalizedString(@" Search" , nil ), self .title];
163+
164+ UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication ] statusBarOrientation ];
165+ if (UIInterfaceOrientationIsPortrait (currentOrientation)) {
166+ self.currentButtonWidth = PORTRAIT_BUTTON_WIDTH;
167+ } else {
168+ self.currentButtonWidth = LANDSCAPE_BUTTON_WIDTH;
169+ }
159170
160171 [super viewWillAppear: animated];
161172}
@@ -177,6 +188,20 @@ - (void)dealloc {
177188 [super dealloc ];
178189}
179190
191+ - (void )willRotateToInterfaceOrientation : (UIInterfaceOrientation)toInterfaceOrientation duration : (NSTimeInterval )duration {
192+ if (UIInterfaceOrientationIsPortrait (toInterfaceOrientation)) {
193+ self.currentButtonWidth = PORTRAIT_BUTTON_WIDTH;
194+ } else {
195+ self.currentButtonWidth = LANDSCAPE_BUTTON_WIDTH;
196+ }
197+
198+ self.deleteButton .width = self.currentButtonWidth ;
199+ self.moveButton .width = self.currentButtonWidth ;
200+ self.renameButton .width = self.currentButtonWidth ;
201+
202+ [super willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
203+ }
204+
180205- (void )deleteElementsFromModelAtIndexPaths : (NSArray *)indexPaths {
181206 NSMutableArray *groupsToRemove = [NSMutableArray arrayWithCapacity: 10 ];
182207 NSMutableArray *enteriesToRemove = [NSMutableArray arrayWithCapacity: 10 ];
@@ -347,6 +372,7 @@ - (void)setSeachBar:(UISearchBar *)searchBar enabled:(BOOL)enabled {
347372 static UIView *overlayView = nil ;
348373 if (overlayView == nil ) {
349374 overlayView = [[UIView alloc ] initWithFrame: searchBar.frame];
375+ overlayView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
350376 overlayView.backgroundColor = [UIColor darkGrayColor ];
351377 overlayView.alpha = 0.0 ;
352378 }
@@ -390,17 +416,17 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
390416 self.deleteButtonTitle = NSLocalizedString(@" Delete" , nil );
391417 self.deleteButton = [[[UIBarButtonItem alloc ] initWithTitle: self .deleteButtonTitle style: UIBarButtonItemStyleBordered target: self action: @selector (deleteSelectedItems )] autorelease ];
392418 self.deleteButton .tintColor = [UIColor colorWithRed: 0.8 green: 0.15 blue: 0.15 alpha: 1 ];
393- self.deleteButton .width = 97 ;
419+ self.deleteButton .width = self. currentButtonWidth ;
394420 self.deleteButton .enabled = NO ;
395421
396422 self.moveButtonTitle = NSLocalizedString(@" Move" , nil );
397423 self.moveButton = [[[UIBarButtonItem alloc ] initWithTitle: self .moveButtonTitle style: UIBarButtonItemStyleBordered target: self action: @selector (moveSelectedItems )] autorelease ];
398- self.moveButton .width = 97 ;
424+ self.moveButton .width = self. currentButtonWidth ;
399425 self.moveButton .enabled = NO ;
400426
401427 self.renameButtonTitle = NSLocalizedString(@" Rename" , nil );
402428 self.renameButton = [[[UIBarButtonItem alloc ] initWithTitle: self .renameButtonTitle style: UIBarButtonItemStyleBordered target: self action: @selector (renameSelectedItem )] autorelease ];
403- self.renameButton .width = 97 ;
429+ self.renameButton .width = self. currentButtonWidth ;
404430 self.renameButton .enabled = NO ;
405431
406432 UIBarButtonItem *spacer = [[[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil ] autorelease ];
0 commit comments