开发者

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:

  1. Open the viewcontroller .m file of the keyboard

  2. Find the - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method

  3. Make 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):

  1. 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:
    1. autoresizemask should at least be autoresizeflexiblewidth in all targets.
    2. Rect set to default(initial) height if autoresizeflexibleheight is not enabled in iPad3.2
    3. Rect set to improper coordinates (x,y) if autoresizeflexibleheight is set in iPad4 do not use autoresizeflexibleheight mask for picker view.
  2. If inputview is not a picker view, its autoresizemasks for flexibleheight should be turned off.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜