簡體   English   中英

旋轉iOS屏幕時,收藏夾視圖單元出現問題

[英]When I rotate iOS screen, collection view cell is going wrong

當我旋轉沒有鍵盤的iOS屏幕時,一切都很好。 但是用鍵盤,我旋轉屏幕,所有單元都出問題了。 我不知道該怎么用英語解釋,所以我上傳了截圖。

這是截圖

快速解決方案

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM