UIView里面有一个UIImageView我现在想让UIVIew适配屏幕大小
NSLayoutConstraint *constraintTop = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0];
NSLayoutConstraint *constraintBottom = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
NSLayoutConstraint *constraintLeft = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
NSLayoutConstraint *constraintRight = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0];
但是UIView不是在中间
setTranslatesAutoresizingMaskIntoConstraints:NO已经设置求解答
NSLayoutConstraint *constraintTop = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1 constant:0];
NSLayoutConstraint *constraintBottom = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
NSLayoutConstraint *constraintLeft = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1 constant:0];
NSLayoutConstraint *constraintRight = [NSLayoutConstraint constraintWithItem:self.imageCropper attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:0];
但是UIView不是在中间
setTranslatesAutoresizingMaskIntoConstraints:NO已经设置求解答
解决方案 »
- iPhone socket 编程
- 新手入门,求介绍Mac入门级练习小程序.
- iphone如何通过http方式上传图片等资源
- IOS越狱开发Hello World
- 重金奖赏 使用 afnetworking 2.0.x 上传 照片至 .net webservice 接收
- 新手来袭,基础问题请教前辈,知道这本《objective-C基础教程》看完,小弟虚心请教,我是C++开发的来学习ios
- iOS 开发特殊json文件的解析
- [菜鸟]sharedApplication
- iOS 导入另一个项目 文件都是红色的
- iOS10系统无法导出应用数据
- 在点击tableview的某一行的时候 怎么切换scrollview里的图片
- 如何获取接口中的视频url地址后直接显示出来
{
NSLayoutConstraint *constraints = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeTop
multiplier:1.0
constant:0];
[self.view addConstraint:constraints];
constraints = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeWidth
multiplier:1.0
constant:0];
[self.view addConstraint:constraints];
constraints = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeHeight
multiplier:1.0
constant:0];
[self.view addConstraint:constraints];
constraints = [NSLayoutConstraint constraintWithItem:view
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:1.0
constant:0];
[self.view addConstraint:constraints];
}
这样写就行了。