切换到横向视图时,帧大小错误地更改了吗?

时间:2019-03-16 19:46:40

标签: ios swift xcode

我正在尝试从Stanford iOS 11 Swift课程制作Graphical Set游戏。在这里,我们使用代码来制作单元格的“网格”,然后使我们能够拥有适合屏幕空间的卡片尺寸。

它使用界限变量进行这些计算。当我将iPhone X从纵向视图更改为横向视图时,宽度保持不变,但高度却增加了??在ViewController中计算出的grid变量分别为纵向和横向提供以下值:

343宽度,461高度 343宽,550.33333333337高度

稍后,尝试将其切换回原位,即使处于纵向模式,它甚至可以移动到692宽170.33333334高度。 为什么我的网格不能产生正确的宽度和高度值?

代码如下:

public class Faculty {
private int groupIterator;
private List<Student> list;

public Faculty() throws Exception {
    list = new ArrayList<Student>();
    Scanner fileIn = new Scanner(new File("---"));

    String line;
    String firstName;
    String lastName;
    int age;
    String CNP;
    int grade;
    boolean leader;

    while(fileIn.hasNextLine()) {
        line = fileIn.nextLine();
        firstName = line;
        line = fileIn.nextLine();
        lastName = line;
        line = fileIn.nextLine();
        age = Integer.parseInt(line);  
        line = fileIn.nextLine();
        CNP = line;
        line = fileIn.nextLine();
        grade = Integer.parseInt(line); 
        line = fileIn.nextLine();
        leader = Boolean.parseBoolean(line);  
        // Here's the key bit - we now pass in the group id based on the list size
        list.add(new Student(firstName,lastName,age,CNP,grade,leader,len(list)/30));
    }

    fileIn.close();
}

class ViewController: UIViewController {

    private var game = SetGame()

    @IBAction func dealThreeMoreCardsButton(_ sender: UIButton) {
        game.dealThreeMoreCards()
    }

    @IBOutlet weak var scoreLabel: UILabel!

    @IBAction func newGame(_ sender: UIButton) {
        game = SetGame()
    }

    @IBOutlet weak var allCardsView: AllCardsView!


    private func updateViewFromModel() {
        if allCardsView.subviews.count > 0 {
            for subview in allCardsView.subviews {
                subview.removeFromSuperview()
            }
        }
        var grid : Grid = Grid(layout: Grid.Layout.aspectRatio(0.5), frame: allCardsView.bounds)
        grid.cellCount = game.tableCards.count
        for cell in 0..<grid.cellCount {
            let newSubview = PlayingCardView(frame: grid[cell]!)
            allCardsView.addSubview(newSubview)
        }
    }

>

0 个答案:

没有答案