I am attaching a UIToolbar to my UITextView as an inputAccessoryView to add a button to close the keyboard. This works great and looks correct when the device is in portrait mode. But itβs hard for me to understand how to resize the toolbar to a lower height used for toolbars when the device is in landscape mode.
I am adding a toolbar to my text delegate -textViewShouldBeginEditing: ::
if (!textView.inputAccessoryView) { UIToolbar *keyboardBar = [[UIToolbar alloc] init]; keyboardBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; keyboardBar.barStyle = UIBarStyleBlackTranslucent; UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissKeyboard:)]; [keyboardBar setItems:[NSArray arrayWithObjects:spaceItem, doneButton, nil]]; [spaceItem release]; [doneButton release]; [keyboardBar sizeToFit]; textView.inputAccessoryView = keyboardBar; [keyboardBar release]; }
I get strange behavior from this code in landscape mode. If I start editing in landscape mode, the terrain height will be on the toolbar, but the Finish button will be drawn halfway on the screen. If I then return to portrait mode, the Finish button will appear in the right place and stay in the right place when I return to landscape mode.
If I start editing in portrait mode, the toolbar is drawn from the portrait height, but the "Finish" button is displayed in the right place. If I then rotate to landscape mode, the toolbar remains upright, but the Finish button is still in the correct position.
Any suggestions for resizing this device while rotating the device? I really hope that there is a more automatic way than manually connecting the magic height numbers in one of the rotation events of the view controller.
Greg
source share