Problem with rotating custom inputView for UITextView
I've written a custom input view that is meant to be used to replace the standard keyboard for a UITextView. If I assign my custom UIView as my UITextView's inputView, it works as expected in both portrait and landscape mode.
The problem occurs when I rotate the device - whenever I do this, my custom UIView expands to fill the entire screen, instead of just covering up the keyboard. I don't have any custom resizing cod开发者_开发百科e anywhere for this - I'm literally just assigning the UIView as the UITextView's inputView property and then rotating the device.
How do I get my custom keyboard view to only occupy the space taken up by the normal keyboard when I rotate the device?
From Apple docs:
You have a lot of flexibility in defining the size and content of an input view or input accessory view. Although the height of these views can be what you’d like, they should be the same width as the system keyboard. If UIKit encounters an input view with an UIViewAutoresizingFlexibleHeight value in its autoresizing mask, it changes the height to match the keyboard.
http://developer.apple.com/library/ios/#Documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/InputViews/InputViews.html#//apple_ref/doc/uid/TP40009542-CH12-SW1
The autoresizingMask is UIViewAutoresizingNone by default if I remember. You autoresizingMask should be UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin.
I had this problem. The way to fix this is:
Open the viewcontroller .m file of the keyboard
Find the
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientationmethodMake it return NO.
My guess is that the view was doing a double rotate.
Make your inputViews autoresizingMask = UIViewAutoresizingNone; Playing with different values of autoresizingMask (version specific) shall help.
Here are some details , which i worked out some time back for iPad (may be this will help you):
- If input view is a Picker view, autoresizing happens by default, which means
the frame is set to required rect. There is a little discrepancy in the way this is done in different Targets/Versions for iPad:
autoresizemaskshould at least beautoresizeflexiblewidthin all targets.- Rect set to
default(initial)height ifautoresizeflexibleheightis not enabled in iPad3.2 - Rect set to improper coordinates (x,y) if
autoresizeflexibleheightis set in iPad4 do not useautoresizeflexibleheightmask for picker view.
- If
inputviewis not a picker view, itsautoresizemasksforflexibleheightshould be turned off.
加载中,请稍侯......
精彩评论