iOS:启动时的大小类和设备方向

时间:2015-09-22 21:23:54

标签: ios swift device-orientation

这是我的问题:将iPhone 6 Plus或iPad旋转到例如LandscapeLeft

假设您的应用具有以下代码(仅作为示例)

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {

    return UIInterfaceOrientationMask.Portrait 
    // mine does use All, but with this case you'll understand my question
}

时,如何检测设备是否应使用垂直或水平布局?
func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator)

被称为?

print(UIScreen.mainScreen().bounds.width < UIScreen.mainScreen().bounds.height)
// will return false, because we started in landscape but the layout will be forced to be vertical here

print(UIApplication.sharedApplication().statusBarOrientation == .LandscapeLeft)
// will return true, because we started in landscape but the layout will be forced to be vertical here

主要问题出现在iPad上,因为两个尺码类都是regular

我很困惑,不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

不要将您的布局视为垂直和水平。只需让应用程序旋转,然后响应尺寸等级或尺寸变化。

在iPad上,尽量避免使用两种布局。只需使用autolayout自动重新调整比例。但是如果你必须在iPad上响应轮换,那么回复import java.io.*; import java.util.Scanner; public class WordsWordsWords { public static void main(String[] args) throws IOException { File temp = new File("words.txt"); // Searches for the file Scanner file = new Scanner(temp); // Creates a Scanner int count = 0; // Finds the number of words that are in the file while (file.hasNextLine()) // Determines how many words are in the file { file.nextLine(); count++; } file.close(); // Closes the scanner String[] wordarr = new String[count]; // Creates an array with each element in the file Scanner listplacement = new Scanner(temp); // Creates a scanner for (int i = 0; i < wordarr.length; i++) // Takes each element and assigns a name to each one. { wordarr[i] = listplacement.nextLine(); } listplacement.close(); // Closes the scanner System.out.println("Your list of names (unsorted):"); // Prints out array of unordered words for (int i = 0; i < wordarr.length; i++) { System.out.println(wordarr[i]); } for (int i = 0; i < wordarr.length - 1; i++) { int low = i; for (int j = i + 1; j < wordarr.length; j++) { if (wordarr[j].compareTo(wordarr[low]) < 0) { low = j; } } String tempo = wordarr[low]; wordarr[low] = wordarr[i]; wordarr[i] = tempo; } System.out.println(); System.out.println("Alphabetized Names:"); for (int n = 0; n < wordarr.length; n++) { System.out.println(wordarr[n]); } System.out.println(); System.out.println("Names with Switched Letters"); for (int i = 0; i < wordarr.length; i++) { String NameString = wordarr[i]; // Changes letters of the code char[] NameChar = NameString.toCharArray(); for (int j = 0; j < NameChar.length; j++) { if (NameChar[j] == 'A') { NameChar[j] = 'E'; } else if (NameChar[j] == 'E') { NameChar[j] = 'I'; } else if (NameChar[j] == 'I') { NameChar[j] = 'O'; } else if (NameChar[j] == 'O') { NameChar[j] = 'U'; } else if (NameChar[j] == 'U') { NameChar[j] = 'A'; } else if (NameChar[j] == 'a') { NameChar[j] = 'e'; } else if (NameChar[j] == 'e') { NameChar[j] = 'i'; } else if (NameChar[j] == 'i') { NameChar[j] = 'o'; } else if (NameChar[j] == 'o') { NameChar[j] = 'u'; } else if (NameChar[j] == 'u') { NameChar[j] = 'a'; } for (j = 0; j < NameChar.length; j++) { System.out.print(NameChar[j]); } } } } } (因为特征集合不会改变)。