简体   繁体   English

iphone 6 plus 上具有 600x600 pt 框架的 UIViews

[英]UIViews with a frame of 600x600 pt on iphone 6 plus with size classes

I am working on an application that is used on all devices (iPad, iPhone).我正在开发一个适用于所有设备(iPad、iPhone)的应用程序。 I use different xib files for iPad and iPhone platforms (just because original app was iPad only and those work great (without any autolayout)).我为 iPad 和 iPhone 平台使用了不同的 xib 文件(只是因为原始应用程序仅适用于 iPad,并且效果很好(没有任何自动布局))。

My iPhone xib files use autolayout and size classes.我的 iPhone xib 文件使用自动布局和大小类。 I have starting screen, i have launch images set okay.我有启动屏幕,我已经设置好了启动图像。 When app starts my view frame is 600x600 in viewDidLoad but its ok, i am not doing anything with it until viewWillAppear.当应用程序启动时,viewDidLoad 中的视图框架为 600x600,但没关系,在 viewWillAppear 之前我不会对它做任何事情。

At this point the frame for xib file is correct (for iphone5 and iphone 6 and iPhone 6+).此时,xib 文件的框架是正确的(对于 iphone5 和 iphone 6 和 iPhone 6+)。 But i have few other views in this xib that are parallel (not subview to any other view) with the main view.但是我在这个 xib 中几乎没有其他视图与主视图平行(不是任何其他视图的子视图)。 And all these other views have a frame of 600x600.所有这些其他视图都有一个 600x600 的框架。

I can set the frame explicitly but then i must resize each subview manually...我可以明确设置框架,但我必须手动调整每个子视图的大小...

If i shut down size classes and use only autolayout, the frame is always iphone 5s size.如果我关闭尺寸类并仅使用自动布局,则框架始终为 iphone 5s 尺寸。

PS I just added all possible launch images (correct sizes) removed size classes and sizes are as follows: Main view - frame = (0 0; 667 375) PS 我刚刚添加了所有可能的启动图像(正确的尺寸)删除的尺寸类别和尺寸如下:主视图 - 框架 = (0 0; 667 375)

View next to it in xib (not subview, but it must also be full screen view) - frame = (0 0; 568 320)在 xib 中查看它旁边的视图(不是子视图,但它也必须是全屏视图)- frame = (0 0; 568 320)

All view sizes are intristic and landscape.所有视图大小都是内在的和景观的。

Edit 1 So my question is: How can other views in xib initialise in correct frame?编辑 1所以我的问题是:xib 中的其他视图如何在正确的框架中初始化? Not 600x600.不是 600x600。

If I usee "Debug in view hierarchy" i can see that all the views that are root views (not as any subviews) except for the main "view" are not right size.如果我使用“在视图层次结构中调试”,我可以看到除主“视图”之外的所有根视图(不是任何子视图)的大小都不正确。 Even though screen bounds are reported correctly, views remain 600x600 size.即使正确报告了屏幕边界,视图仍保持 600x600 大小。

Edit 2 This question asks similar question: iOS 8 top layout guide auto layout problems But no answer has been given that would universally solve the problem.编辑 2这个问题提出了类似的问题: iOS 8 top layout guide auto layout questions 但没有给出可以普遍解决问题的答案。

If i add all those other views as subviews to my main view, frame gets sized correctly (thanks to autolayout), but this is not an option for me since i cannot have them all as subviews at launch.如果我将所有其他视图作为子视图添加到我的主视图中,框架的大小会正确(由于自动布局),但这对我来说不是一个选择,因为我不能在启动时将它们全部作为子视图。

So this is how i made it work for me:所以这就是我让它为我工作的方式:

As soon as i add my subview which has bad frame, i add autolayout constraints to it like this:一旦我添加了具有错误框架的子视图,我就会向它添加自动布局约束,如下所示:

[self.view addSubview:_subviewFromSameXib];  //naming just for example

_subviewFromSameXib.translatesAutoresizingMaskIntoConstraints = NO;


[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_subviewFromSameXib
                                                          attribute:NSLayoutAttributeTop
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeTop
                                                         multiplier:1.0
                                                           constant:0.0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_subviewFromSameXib
                                                          attribute:NSLayoutAttributeLeading
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeLeading
                                                         multiplier:1.0
                                                           constant:0.0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_subviewFromSameXib
                                                          attribute:NSLayoutAttributeBottom
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeBottom
                                                         multiplier:1.0
                                                           constant:0.0]];

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:_subviewFromSameXib
                                                          attribute:NSLayoutAttributeTrailing
                                                          relatedBy:NSLayoutRelationEqual
                                                             toItem:self.view
                                                          attribute:NSLayoutAttributeTrailing
                                                         multiplier:1.0
                                                           constant:0.0]];

This does the following: After adding my subview it adds new constraints that tell this subview that it must size according to its superview.这将执行以下操作:在添加我的子视图之后,它添加了新的约束,告诉这个子视图它必须根据其父视图来调整大小。

This fixes my problem but does not solve the main issue: multiple views in xib do not get sized according to screen bounds.这解决了我的问题,但没有解决主要问题:xib 中的多个视图不会根据屏幕边界调整大小。 Only the first one does.只有第一个可以。

I am using xibs not storyboards btw.顺便说一句,我使用的是xibs而不是故事板。 And i should add that playground displays all views correctly on all devices.我应该补充一点,游乐场在所有设备上正确显示所有视图。 Only on runtime they get messed up.只有在运行时它们才会搞砸。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UIScrollView内容大小固定为600x600(Main.storyboard大小) - UIScrollView content size fixed to 600x600(Main.storyboard size) UINavigationController大小的UIViewController.view在iOS 9上变为600x600,并且从未改变过 - UIViewController.view in UINavigationController size become 600x600 on iOS 9, and never changed 使用Autolayout的XIB中的UIView总是600x600 - UIView in XIB using Autolayout is always 600x600 具有自动布局的scrollview大小:紧凑型/任何尺寸级别的框架均为600x480,大于iphone5? - scrollview size with Autolayout: frame is 600x480 in compact/Any size class, bigger than iphone5? 为什么视图的帧宽度通过自动布局总计600到600 - Why is frame width of the view alway 600 by 600 with autolayout 大小类来区分iPhone 5,6和6 Plus? - Size Classes to distinguish between iPhone 5, 6 and 6 Plus? iPhone 6加上横向模拟器尺寸大小 - iPhone 6 plus simulator size classes in landscape iPhone 6 Plus及更高版本的Xcode约束和大小类 - Xcode constraint and size classes for iphone 6 plus and up 来自xib的自定义UIView始终具有600 pt的高度(UIView-Encapsulated-Layout-Height约束) - Custom UIView from xib always has height of 600 pt (UIView-Encapsulated-Layout-Height constraint) 更新的尺寸类别的xib在iPhone 6和iPhone 6 Plus中不显示iAd - Renewed xib with Size Classes not showing iAds in iPhone 6 and iPhone 6 Plus
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM