[英]When I rotate iOS screen, collection view cell is going wrong
快速解決方案
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解決方案
[[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];
}
我將view.frame.width
用於自動布局約束。
bubbleWidthAnchor = bubbleView.widthAnchor.constraintEqualToConstant(view.frame.width/5*3)
像這樣。
代替那個
bubbleWidthAnchor = bubbleView.widthAnchor.constraintEqualToConstant(UIScreen.mainScreen().bounds.width/5*3)
而且看起來還不錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.