故事板与模拟器没有约束条件适用

时间:2017-09-22 17:57:31

标签: ios uiimageview constraints xcode9

很可能在经过这么多个小时的工作之后我做了很多混乱,但我不明白发生了什么......

在我给你看的照片中,你可以看到故事板lamm。橙色箭头表示我在iPhone SE上工作,而我的模拟器是iPhone SE和IPhone 8 plus ..

正如您所看到的,即使我已经设置了约束,这两个模拟器仍有两种不同的视图。 enter image description here

enter image description here

UIImageView对它有一个渐变效果,如果我让UIImageView在所有设备上都能完美呈现,即使我正在处理故事板Iphone I ..我不明白为什么这可以帮助我?

我还向您展示了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;
}];

}

2 个答案:

答案 0 :(得分:2)

您正在致电:

gradientMask.frame = _images.bounds;
viewDidLoad()中的

。此时,自动布局尚未布置所有视图,因此您的_images.bounds与故事板中的内容相匹配。

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

您需要在自动布局完成后将渐变蒙版创建/大小调整移动到点,或者,我建议的是,将UIImageView子类化以添加渐变在那里进行遮罩,并在layoutSubviews()中自动调整大小。

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

答案 1 :(得分:-2)

试试这个......

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

然后运行你将获得正确的视图。