似乎在Xcode 8上viewDidLoad,所有viewcontroller子视图都具有相同的1000x1000大小.奇怪的是,但没关系,viewDidLoad从来没有一个正确调整视图大小的好地方.
但是viewDidLayoutSubviews!
在我当前的项目中,我尝试打印按钮的大小:
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
NSLog(@"%@", self.myButton);
}
Run Code Online (Sandbox Code Playgroud)
日志显示myButton的大小为(1000x1000)!然后,如果我登录按钮单击,例如,日志显示正常大小.
我正在使用autolayout.
这是一个错误吗?
我将我的项目转换为iOS 10和XCode 8的新测试版.在我使用的应用程序的所有三个区域中:
imageView.layer.cornerRadius = imageView.frame.size.width/2
imageView.clipsToBounds = true
Run Code Online (Sandbox Code Playgroud)
相关图像根本不显示.我尝试清理项目以及构建文件夹,重新启动设备,尝试各种模拟器,重新添加imageView,以编程方式设置关联,UIImage而不是从资产中选择一个.
卸下clipsToBounds线示出了矩形图像无论masksToBounds是true或false.如何在XCode8/iOS10中制作圆形图像?
编辑:该项目是Swift 2.x,尚未更新为Swift 3.0语法.
- (IBAction)btnA:(id)sender {
if(self.height.constant == 300) {
self.height.constant = 50;
} else {
self.height.constant = 300;
}
[self.subView1 setNeedsUpdateConstraints];
[UIView animateWithDuration:1.0 animations:^{
[self.subView1 layoutIfNeeded];
}];
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个代码,但iOS10它没有动画它只是跳跃增加和减少mySubview1高度.为什么?
相同的代码工作正常 iOS9
从iOS 10开始,我注意到动画布局更改(layoutIfNeeded())不是动画.这是我的UIView扩展,在iOS 9及更低版本上运行良好.
func slideIn(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = 0
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
}
}
func slideOut(from edgeConstraint: NSLayoutConstraint, withDuration duration: Double = 0.25, finishedAnimating: (() -> Void)? = nil) {
dispatch_async(dispatch_get_main_queue()) {
edgeConstraint.constant = -self.frame.height
UIView.animateWithDuration(duration,
delay: 0.0,
options: .BeginFromCurrentState,
animations: { self.layoutIfNeeded() },
completion: { didComplete in
finishedAnimating?()
})
} …Run Code Online (Sandbox Code Playgroud) ios ×4
ios10 ×3
autolayout ×2
xcode8 ×2
animation ×1
constraints ×1
objective-c ×1
swift ×1
uiimage ×1
uiimageview ×1
uiview ×1