问题与自动布局在iOS 8(code完美的作品在iOS 7) [英] Issue with Auto Layout on iOS 8 (code works perfectly on iOS 7)

查看:105
本文介绍了问题与自动布局在iOS 8(code完美的作品在iOS 7)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用自动布局和内置应用程序的一切仍然有效,当我在我的iOS运行7设备如预期,但是当我在一个运行iOS的设备8我的一些约束条件去有点古怪。

I have an app that was built using auto-layout and everything still works as expected when I run it on my iOS 7 device, however when I run it on an iOS 8 device some of my constraints go a little wacky.

我居然经历了另一个应用程序类似的问题,但它不是一个大问题。现在,我开始怀疑它在iOS的8 SDK错误或是否有处理在iOS8上汽车的布局,我不知道的新途径。

I actually experienced a similar issue in another app but it wasn't a big issue. Now, I'm starting to wonder if it is a bug in the iOS 8 SDK or if there is a new way of handling auto layout in iOS8 that I'm not aware of.

下面是我的设置:
我有一个的UIView 与嵌入了的UIImageView 。无论是视图和图像视图有限制的牵制下,领导和放大器;后缘其与superviews常数= 0

Here is my setup: I have a UIView with a UIImageView embedded inside it. Both the view and the image view have constraints pinning their bottom, leading & trailing edges to their superviews with constant = 0.

的UIView 也有其固定到它的父顶部边缘,我有一个IBOutlet连接约束,以编程方式调整。在的UIImageView 的第四个约束它的高度固定在装置的高度(在我的案件568)。

The UIView also has its top edge pinned to its superview and I have an IBOutlet connected to the constraint in order to adjust it programatically. The UIImageView has a fourth constraint fixing its height to the height of the device (in my case 568).

下面是我期待/ iOS中7实现的行为:
我试图缩小容器视图的高度,使图像视图顶部的W / O宽高比改变被切断(有点貌似你裁剪图像关闭的顶部)......这是为什么我已经固定图像视图和底边的高度。

Here is the behavior I am expecting/achieving in iOS 7: I am trying to shrink the height of the container view and cause the top of the image view to be cut off w/o the aspect ratio changing (sort of looks like you cropped the top of the image off)...this is why I have pinned the height of the image view and the bottom edge.

实际上发生在iOS8上什么:
容器视图收缩预期(它保持固定在两侧和放大器;底部&放大器;高度收缩)。在的UIImageView 的行为就好像它与cosntant == 0,而不是切断图像的顶部顶部空间限制,整个图像逐渐缩小。由于我在 AspectFit 模式下,图像,两侧捏住以及保持纵横比相同(但ImageView的本身仍然固定在领导,拖尾和放大器;底部边,因为它应该)。

What actually happens in iOS8: The container view shrinks as expected (it stays pinned to the sides & bottom & the height shrinks). The UIImageView behaves as if it had a top space constraint with cosntant == 0. Instead of cutting off the top of the image, the whole image shrinks down. Since I have the image in AspectFit mode, the sides pinch in as well to keep the aspect ratio the same (but the imageView itself remains pinned to the leading, trailing & bottom edges as it should).

我是怎么做的:
我有一个从我的code的另一部分触发调整挂在IBOutlet中顶部空间约束的通知。它调用该方法其实非常简单:

How I do it: I have a notification that fires from another part of my code to adjust the top-space constraint hooked up to the IBOutlet. The method it calls is really quite simple:

- (void) setTopSpaceForContainerView:(NSNotification*) notif{
    containerView_TopSpace.constant = [[notif.userInfo objectForKey:kTopSpace] intValue];
    [self.view setNeedsUpdateConstraints];
    [self.view setNeedsLayout];
}

任何人有类似的经历?我试图找到一个解决办法,但iOS的8只似乎决心要缩小我的形象。

Anyone else have a similar experience? I'm trying to find a workaround, but iOS 8 just seems determined to shrink my image.

由于一吨!

推荐答案

这绝对是一个iOS 8的错误。我可以通过发送 setNeedsLayout 到容器视图(图像视图的上海华)来解决它。

This is definitely an iOS 8 bug. I was able to work around it by sending setNeedsLayout to the container view (the superview of the image view).

我看到你发送 setNeedsLayout self.view 。如果code是在你的视图控制器,那么我想<$​​ C $ C> self.view 不是容器视图。试着发送 setNeedsLayout 直接在容器视图。

I see that you're sending setNeedsLayout to self.view. If that code is in your view controller, then I guess self.view is not the container view. Try sending setNeedsLayout to the container view directly.

示范项目是这里

这篇关于问题与自动布局在iOS 8(code完美的作品在iOS 7)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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