ios 如何使界面生成器中的 uitableview 与 4 英寸 iPhone 兼容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12406505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 20:05:59  来源:igfitidea点击:

How to make a uitableview in interface builder compatible with a 4 inch iPhone

iosios5ios6

提问by Anand

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

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

There are three options in Xcode 4.5:

Xcode 4.5 中有三个选项:

  • Freeform
  • Retina 3.5 full screen
  • Retina 4 full screen
  • 自由形式
  • Retina 3.5 全面屏
  • 视网膜 4 全面屏

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

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

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

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

How should one do it using Interface Builder?

应该如何使用 Interface Builder 做到这一点?

EDIT

编辑

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

我的问题是针对 iphone 5 视网膜 4 英寸屏幕。检查具有状态栏和导航栏的视图的大小时,这里是 self.view.frame.size.height/width, frame 320.000000 x 416.000000 的值,以防我选择 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.

自动调整选项设置为使视图向所有方向扩展,即启用所有支柱和弹簧。

EDITFor testing in iOS6 simulator, If I set the following in code

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

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);

I get the following output

我得到以下输出

 320.000000 - 546.000000
 320.000000 - 546.000000

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

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

MY SOLUTION

我的解决方案

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

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

回答by M. Alvanez

BEWAREof 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.

当心,如果您的应用程序,你现在actionsheets设置大小属性来“视网膜4全屏”的。此解决方案实际上将主窗口的尺寸设置为 iPhone 5 的尺寸。在我的情况下,当您尝试显示操作表时,在 iPhone 4 中设置此受影响的显示,因为它会尝试从可视屏幕下方显示它.

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.

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

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

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

}

回答by fannheyward

Choose your xib file and change the Sizeattribute.

选择您的 xib 文件并更改Size属性。

enter image description here

在此处输入图片说明

回答by WaaleedKhan

From what i have understand u want to create a table view which can be applicable to both iPhone 4 and 5. First thing first i havnt tried the Xcode 4.5, but the code

据我所知,你想创建一个适用于 iPhone 4 和 iPhone 5 的表格视图。首先我没有尝试过 Xcode 4.5,但是代码

 CGRect fullScreenRect = [[UIScreen mainScreen] bounds];
 theTableView.frame = CGRectmake = (0,0,fullScreenRect.width,fullScreenRect.height);

the fullScreenRectwill return the bound of the current device whether its 3.5 or 5 inch. and u can set the height and width dynamically.

fullScreenRect将返回绑定当前设备是否其3.5或5英寸。并且您可以动态设置高度和宽度。

Let me know if it worked..

让我知道它是否有效..

Cheers

干杯

W

回答by AliSoftware

Settings like choosing from "freeform", "Retina 3.5" or "Retina 4" in Interface Builder are in the "Simulatedmetrics" section of the right panel (note the emphasis added).

在界面生成器中从“自由格式”、“Retina 3.5”或“Retina 4”中进行选择等设置位于右侧面板的“模拟指标”部分(注意添加的重点)

This means that they are only used to show you how the view will look when displayed at those dimensions. Typically you use this to know at design time what space you will have to layout your views. But the UIView of a UIViewController is always resized when displayed on screen at the end.

这意味着它们仅用于向您展示在这些维度上显示时视图的外观。通常,您可以在设计时使用它来了解布局视图所需的空间。但是 UIViewController 的 UIView 在最后显示在屏幕上时总是会调整大小。

For example if you know that you will have a status bar and a NavigationBar at the top, and a TabBar at the bottom, you will have less space to organize your remaining view on the screen, so selecting these in the "Simulated Metrics" section of the panel will help you see which space you have in the view and avoid placing elements at say y=460 that will go offscreen at runtime due to these NavBar and TabBar.

例如,如果您知道顶部有一个状态栏和一个导航栏,底部有一个 TabBar,那么您将有更少的空间来组织屏幕上的剩余视图,因此请在“模拟指标”部分中选择这些面板的 将帮助您查看视图中的空间,并避免将元素放置在 y=460 处,因为这些 NavBar 和 TabBar 在运行时会离开屏幕。

But at the end, the UIViewController will resize its view so that it takes the maximum space available, moving the subviews according to the AutoresizingMask properties (the struts & springs you can configure in the Size Inspector pane in IB).

但最后,UIViewController 将调整其视图的大小,以便占用最大可用空间,根据 AutoresizingMask 属性(您可以在 IB 的 Size Inspector 窗格中配置的支柱和弹簧)移动子视图。

In conclusion, the only thing you have to do is:

总之,您唯一要做的就是:

  • Prefer choosing the "Retina 3.5" simulated metric for your view to see in Interface Builder the smallest size you may have when this view is displayed (helping you avoid to placing views and controls in a portion of you screen that will be only visible in 4" screens but not on 3.5" screens and desining your view by keeping in mind the smallest common zone)
  • Configure your AutoResizing Masks correctly (or use AutoLayout and constraints if you plan to release your app for iOS6 only and not iOS4 or iOS5) so that your views will me rearranged correctly when the screen is higher (Retina 4").
  • 更喜欢为您的视图选择“Retina 3.5”模拟指标,以便在 Interface Builder 中查看显示此视图时您可能拥有的最小尺寸(帮助您避免将视图和控件放置在屏幕的一部分中,这些部分只能在 4 “屏幕但不在 3.5”屏幕上,并通过记住最小的公共区域来设计您的视图)
  • 正确配置您的 AutoResizing Masks(如果您计划仅针对 iOS6 而不是 iOS4 或 iOS5 发布您的应用程序,则使用 AutoLayout 和约束),以便您的视图在屏幕较高时正确重新排列(Retina 4")。

回答by Frank Wu

if your interface is using Storyboard:

如果您的界面使用 Storyboard:

Open *.Storyboard with "Text Editor"

使用“文本编辑器”打开 *.Storyboard

and go the end bottom find <simulatedScreenMetrics key="destination" type="retina4"/>

然后走到尽头底部找到 <simulatedScreenMetrics key="destination" type="retina4"/>

delete type="retina4"

删除 type="retina4"

then it will be default size in 3.5"

那么它将是 3.5" 的默认大小