开发者

UIView coordinate transforms on rotation during keyboard appearance

开发者 https://www.devze.com 2022-12-29 02:28 出处:网络
iPad app; I\'m trying to resize my view when the keyboard appears.It amounts to calling this code at appropriate times:

iPad app; I'm trying to resize my view when the keyboard appears. It amounts to calling this code at appropriate times:

 CGRect adjustedFrame = self.frame;
  adjustedFrame.size.height -= keyboardFrame.size.height;
 [self setFrame:adjustedFrame];

Using this technique for a view contained in a uisplitview-based app works in all 4 orientations, but I've since discovered that a vanilla uiview-based app does not work.

What happens is that apparently the uisplitview is smart enough to convert the coordinates of its subviews (their frame) such that the origin is in the "viewer's top left" regardless of the orientation. However, a uiview is not able to correctly report these coordinates. Though the 开发者_运维技巧origin is reported as (0,0) in all orientations, the view's effective origin is always as if the ipad were upright.

What is weird about this is that the view correctly rotates and draws, but it always originates in the literal device top left. How can I get the view to correctly make its origin the "top left" to the viewer, not the device's fixed top left? What am I missing? Please, for something so trivial I've spent about 6 hours on this already with every brute force technique and research angle I could think of.

This is the original source which doesn't work in this case:

move up UIToolbar


OK, I don't know what the ACTUAL answer is to the original question, but I can say with certainty that one way to resolve the issue is to always ensure that you don't manipulate a viewController's view directly. Always wrap your view inside a container view inside the main "view", then have that container view adjust its position etc as needed. Works exactly as the splitview does, probably because in both cases now the view in question is a subview of the main "view". What a relief!

0

精彩评论

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