如何在界面生成器中制作与 4 英寸 iPhone 兼容的 uitableview [英] How to make a uitableview in interface builder compatible with a 4 inch iPhone

查看:17
本文介绍了如何在界面生成器中制作与 4 英寸 iPhone 兼容的 uitableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在界面生成器中制作与 4 英寸 iphone5 和旧 iPhone 4/4s 兼容的 uitableview?

How do I make a uitableview in interface builder compatible with 4 inch iphone5, and the older iPhone 4/4s?

Xcode 4.5 中有三个选项:

There are three options in Xcode 4.5:

  • 自由格式
  • 视网膜 3.5 全屏
  • 视网膜 4 全屏

如果我选择 Retina 4,那么在 3.5 英寸手机中它会越过/溢出屏幕边框

If I chose Retina 4, then in the 3.5 inch phone it crosses/overflows the screen border

使用代码,我可以相应地设置框架,但是使用界面生成器有什么用呢?

Using code, I can set the frame accordingly, but then what is the use of using interface builder?

应该如何使用 Interface Builder?

How should one do it using Interface Builder?

编辑

我的问题是 iPhone 5 Retina 4 英寸屏幕.在检查具有状态栏和导航栏的视图的大小时,这里是 self.view.frame.size.height/width 的值,如果我选择 freeform/none/retina 3.5,框架为 320.000000 x 416.000000

My question is for iphone 5 retina 4 inch screen. When inspecting the size of the view which has a status bar and navigation bar, here is the value of self.view.frame.size.height/width, frame 320.000000 x 416.000000 in case I choose freeform/none/retina 3.5

设置了自动调整大小选项,以便视图向所有方向扩展,即启用所有支柱和弹簧.

The autoresizing options are set so that the view expands in all directions, that is all struts and springs are enabled.

编辑为了在 iOS6 模拟器中进行测试,如果我在代码中设置以下内容

EDIT For testing in iOS6 simulator, If I set the following in code

self.tableView.frame    = CGRectMake(0, 0, 320, 546);
self.tableView.bounds   = CGRectMake(0, 0, 320, 546);
self.view.frame         = CGRectMake(0, 0, 320, 546);
self.view.bounds        = CGRectMake(0, 0, 320, 546);
NSLog(@"%2f - %2f", self.view.bounds.size.width, self.view.bounds.size.height);
NSLog(@"%2f - %2f", self.tableView.bounds.size.width, self.tableView.bounds.size.height);

我得到以下输出

 320.000000 - 546.000000
 320.000000 - 546.000000

并且从顶部算起 480 像素以下的所有行都是不可选择的,因为视图"仍然认为它们超出了界限.

And All the rows below the 480 px from the top are not selectable, as the 'view' still thinks they are out of bounds.

我的解决方案

将所有屏幕的大小设置为 Retina 4,包括主窗口 xib 文件.在此之后,即使在 iphone 4 上它似乎也能正常工作.并且所有低于 480px 的行现在都可以在 iOS 6 模拟器中点击

Set the size to Retina 4 for all screens, even the main window xib file. It seems to work fine even on the iphone 4 after this. And all rows below 480px are now clickable in iOS 6 simulator

推荐答案

注意如果您在应用程序中显示操作表,请将 size 属性设置为Retina 4 Full Screen".此解决方案实际上将主窗口的尺寸设置为 iPhone 5 的尺寸.在我的情况下,当您尝试显示操作表时在 iPhone 4 中设置此受影响的显示,因为它会尝试从可视屏幕下方显示它.

BEWARE of setting the size attribute to "Retina 4 Full Screen" if you present actionsheets in your application. This solution actually sets the dimensions of the main Window to the dimensions of the iPhone 5. In my case, setting this affected display in the iPhone 4 when you try to show an action sheet because it will try to show it from below the viewable screen.

适用于所有情况的正确解决方案是将大小设置为 none 并在应用程序委托 didfinishloading 方法中检测屏幕大小并将主窗口设置为该大小或将 rootviewcontroller 的视图设置为该大小.操作表将正常工作.

The proper solution that works for all cases is to set the size to none and detect the screensize in the app delegate didfinishloading method and set the main window to that size or set the rootviewcontroller's view to that size. Actionsheets will work correctly.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

self.window.frame = CGRectMake(0, 0, [[UIScreen mainScreen]bounds].size.width, [[UIScreen mainScreen]bounds].size.height);

}

这篇关于如何在界面生成器中制作与 4 英寸 iPhone 兼容的 uitableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆