简体   繁体   English

旋转iOS屏幕时,收藏夹视图单元出现问题

[英]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. 我不知道该怎么用英语解释,所以我上传了截图。

This is a 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.

相关问题 旋转设备时,iOS模拟器为什么显示空白屏幕? - Why is iOS simulator displaying blank screen when I rotate device? 单击表格视图单元格时转到另一个视图 - Going to another view when I click a tableview cell 轻按时,iOS Animate表格视图单元会变为全屏 - iOS Animate table view cell into full screen when tapped 长按模式下的收藏夹视图时,如何移动收藏夹视图单元格并在iOS中重新排列它们? - How to move collection view cell & rearrange them in iOS when collection view in long press mode? 当我单击第一个表格视图的表格视图单元格时进入第二个表格视图? - Going into a second table view when i click on a table view cell of a first table view? 重新定义时更改设计集合视图单元格 - Change design collection view cell when I redimensioned 检测iOS UICollectionCell何时离开屏幕 - detecting when an iOS UICollectionCell is going off screen iOS:使用CollectionView图像单元旋转屏幕后出现故障 - IOS : Glitch after rotate screen with CollectionView image cell 集合视图单元格的动态宽度-Xamarin iOS - Dynamic width of collection view cell - Xamarin iOS iOS集合视图中的不同单元格大小 - Different Cell size in a collection view in ios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM