[英]When I rotate iOS screen, collection view cell is going wrong
when I rotate iOS screen without keyboard , it's all fine. 当我旋转没有键盘的iOS屏幕时,一切都很好。 but with keyboard, I rotate screen, all the cell is going wrong.
但是用键盘,我旋转屏幕,所有单元都出问题了。 I don't know how to explain in English, so I uploaded Screenshot.
我不知道该怎么用英语解释,所以我上传了截图。
Swift Solution 快速解决方案
override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.currentDevice().orientation.isLandscape.boolValue {
print("Landscape")
view.endEditing(true)
} else {
print("Portrait")
view.endEditing(true)
}
}
Objective-C Solution Objective-C解决方案
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
if ( ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) )
{
// do something for Portrait mode
[[self view] endEditing:YES];
}
else if(([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft))
{
// do something for Landscape mode
[[self view] endEditing:YES];
}
I used view.frame.width
for auto-layout constraints. 我将
view.frame.width
用于自动布局约束。
bubbleWidthAnchor = bubbleView.widthAnchor.constraintEqualToConstant(view.frame.width/5*3)
like this. 像这样。
Instead of that 代替那个
bubbleWidthAnchor = bubbleView.widthAnchor.constraintEqualToConstant(UIScreen.mainScreen().bounds.width/5*3)
and it looks fine. 而且看起来还不错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.