横向/纵向冲突 - iOS
就在我以为我已经解决了一切的时候..我遇到了这个问题。
场景。
我有一个简单的表视图。并在导航项的 titleView 中带有搜索栏。 SearchBar 通过视图控制器工具栏中的 uibarbuttonitem 添加到 navItems titleView 中。
现在,通常
在使用 [beginResponder] 启动搜索栏后,键盘就会显示。它发出一个通知“KeyboardDidShow”,这是我计算 UIKeyboard 的高度并相应地设置 tableView 的高度(缩短它)的地方。
旋转 - 来回横向/纵向,一切正常。 -(void)didRotateInferfaceOrientation 被调用,一切都很酷。
问题就在这里。
当键盘处于活动状态时,它有一个 Google“搜索”按钮,这会推送到一个新视图 - webviewcontroller。
问题是,这个
时候,[PORTRAIT]ViewController [SearchBar with Keyboard active] -->点击搜索 --> [肖像]WebViewController -->将设备方向更改为[横向] --> [Landscape]WebViewController更改为横向--->问题在于,用户点击回 uiViewController[Landscape] 时,
不会调用 -didRotatefromInterfaceOrientation 方法。不知何故,tableView 的高度被搞乱了。尽管视图正在完美旋转。
我这里缺少什么吗..
将不胜感激任何帮助。 。谢谢
Just when i thought I had everything figured out .. i got this problem.
the scenario.
I got a simple tableView. and with a search bar in navigation item's titleView. The SearchBar is added to navItems titleView via a uibarbuttonitem in view controllers toolbar.
NOW, normally
After initiating the searchbar with [beginResponder] the keyboard shows up. And It sends out a notification "KeyboardDidShow" which is where i calculate the UIKeyboard's height and set the tableView's height accordingly (Shorten it).
ON Rotation - to and fro landscape/portrait, everything works fine.
-(void)didRotateInferfaceOrientation is called and everythings kool.
Heres the problem.
When the keyboard is active, it has a Google "search" button, this pushes to a new view - webviewcontroller.
the problem is, this
When, [PORTRAIT]ViewController [SearchBar with keyboard active] --> taps Search --> [Portrait]WebViewController --> Change Device Orientation to [Landscape] --> [Landscape]WebViewController changes to landscape ---> HERES THE PROBLEM, user taps back to uiViewController[Landscape]
the method -didRotatefromInterfaceOrientation isnt called. and somehow the tableView height is messed up. Though the view is rotating perfectly.
Is there something im missing here..
would appreciate any help. .thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当用户点击返回时,-didRotatefromInterfaceOrientation 将不会被调用。您需要检查 viewWillAppear 中的方向(或在点击背面返回之前调用 viewDidLoad),然后为所选方向调用正确的布局。
在所有 (BOOL)shouldRotate... 方法中,您应该调用一个单独的方法,以确保您的布局对于设备方向是正确的。
When user taps back, -didRotatefromInterfaceOrientation will not be called. You need to check orientation in viewWillAppear (or call viewDidLoad, prior to returning from tap on back), and then call the proper layout for the chosen orientation.
In all of your (BOOL)shouldRotate... methods, you should be call a separate method to ensure your layout is correct for the device orientation.
我最近在我的一个应用程序中遇到了类似的问题,不完全是我们的问题,但不要打扰,你应该看到我要做什么:我想简单地旋转使用presentModalViewController显示的viewController...不幸的是它没有确实有效,尤其是在 iOS 4 之前操作系统的旧 iPhone 上......所以我需要以编程方式旋转!只需获取您的屏幕尺寸,使用 CGAffineTransform 或类似的东西并更改尺寸,然后您就应该完成......
如果您感兴趣,我可以发布一堆代码,所以请告诉我!
编辑:
这还包括在旋转到横向时删除 TabBar 以获得更多空间......享受:)
I got a similar problem in one of my applications recently, not exactly our problem but don't bother, you should see what I'm heading for: I wanted to simply rotate an viewController displayed using presentModalViewController...Unfortunatly it didn't really worked put, especially on old iPhone with OS prior to iOS 4...So I needed to rotate programatically! Just get your screen size, use CGAffineTransform or something like that and change the sizes and then you should be done...
If your interested I could post a bunch of code, so let me know!
EDIT:
This also includes removing a TabBar when rotating to landscape to get some more space...enjoy :)
您可以在 viewWillAppear 上手动调用 didRotateFromInterfaceOrientation 并自行传递方向(即 [UIApplication sharedApplication].statusBarOrientation)。
You could call didRotateFromInterfaceOrientation manually on viewWillAppear and just pass an orientation yourself (i.e. [UIApplication sharedApplication].statusBarOrientation).