故事板Vs的模拟器没有约束应用于

问题描述:

最有可能我做了很多混乱的这么多小时的工作后,但我不明白这是怎么回事...故事板Vs的模拟器没有约束应用于

在照片中,我告诉你下面你可以看故事板lamm。橙色箭头表示我正在使用iPhone SE,而我的模拟器是iPhone SE和iPhone 8 plus。

正如您所看到的,尽管我已经设置了约束条件,但两个模拟器有两个不同的视图。 enter image description here

enter image description here

的UIImageView上有一个渐变的效果,如果我带的UIImageView完美旁观,即使我的工作故事板IPHONE我的所有设备。我不明白为什么这可以帮助我?

我还告诉你了UIImageView的代码

- (void)viewDidLoad { 
[super viewDidLoad]; 
CAGradientLayer *gradientMask = [CAGradientLayer layer]; 
gradientMask.frame = _images.bounds; 
gradientMask.colors = @[(id)[UIColor whiteColor].CGColor, 
         (id)[UIColor clearColor].CGColor]; 

_images.layer.mask = gradientMask; 

gradientMask.startPoint = CGPointMake(0.8, 0.0); 
gradientMask.endPoint = CGPointMake(0.8, 0.8); 

gradientMask.colors = @[(id)[UIColor clearColor].CGColor, 
         (id)[UIColor whiteColor].CGColor, 
         (id)[UIColor whiteColor].CGColor, 
         (id)[UIColor clearColor].CGColor]; 
gradientMask.locations = @[@0.0, @0.0, @0.8, @1.0]; 

_images.contentMode = UIViewContentModeScaleAspectFill; 

UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]; 
UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:effect]; 
blur.frame = CGRectMake(_images.frame.origin.x, _images.frame.origin.y, _images.frame.size.width, _images.frame.size.height +50); 
[_images addSubview:blur]; 

[UIView animateWithDuration:.1 animations:^{ 
    blur.alpha = .7; 
}]; 

}

+0

你应该也显示约束,看起来像那些问题 –

+0

只是我或你只是设置高度和宽度,而不是将锚定在两侧? –

+0

@MilanNosáľ我编辑了我的帖子 – kAiN

要调用:

gradientMask.frame = _images.bounds; 
viewDidLoad()

。此时,自动布局尚未布置所有视图,因此您的_images.bounds与您在Storyboard中的内容相符。

结果是图像视图的右侧是被遮盖掉,因为渐变图层没有覆盖它。

您需要可以移动渐变面具制作/后自动布局大小到一个点完成,或者,我会建议,被继承UIImageView添加渐变面具出现,并使其自动调整它在layoutSubviews()

编辑:作为一个附注,你不应该把视图动画放在viewDidLoad() - 很可能你甚至不会看到它。

+0

其实这个问题就是这个!非常感谢...我仍然需要一点帮助,我的uicollectionview ..单元不正确地响应各种设备之间的collectionView Flow布局冲动,我认为这总是一个约束问题..我只是看到它的iPhone SE我怎样才能解决这个问题? – kAiN

试试这个....

1.首先选择u需要哪个电话,如果u需要iPhone 8,然后选择MainStoryboard的模拟器iPhone 8和下方有一个选项来选择手机的方向,然后选择视图iPhone 8. 2.在ViewController中放置图像 3.然后在Xcode的一侧选择图像,然后选择自动调整选项水平和垂直线(勾选)。

然后运行你会得到正确的看法。