2017-04-18 5 views
1

Ich möchte die Höhe des Popover im Querformat ändern, aber es funktioniert nur im Hochformat.Höhe für Popover im Querformat einstellen

Ich möchte es ist Höhe gleich screenSize.height * 0.7, aber es funktioniert nicht mit meinem Code unten.

enter image description here

Hier ist mein Code:

if let orientation = UIDevice.current.value(forKey: "orientation") as? Int { 
     let diamondViewController = DiamondViewController() 
     diamondViewController.mode = .buyDiamondPopup 
     diamondViewController.resetBackgroundColor = { 
      self.view.backgroundColor = .clear 
     } 

     let screenSize = UIScreen.main.bounds 
     if orientation == 3 { // LandscapeRight 
      diamondViewController.preferredContentSize = CGSize(width: screenSize.width * 0.6, height: 
       screenSize.height * 0.7) 
     } else { 
      diamondViewController.preferredContentSize = CGSize(width: screenSize.width - 60, height: 
       min(screenSize.height - 180, CGFloat(5 * 70 + 110))) 
     } 
     diamondViewController.modalPresentationStyle = .popover 
     if let popover = diamondViewController.popoverPresentationController { 
      popover.permittedArrowDirections = .init(rawValue: 0) 
      popover.sourceView = self.view 
      popover.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) 
      popover.delegate = self 
      self.view.backgroundColor = UIColor.black.withAlphaComponent(0.5) 
      self.present(diamondViewController, animated: true, completion: nil) 
     } 
    } 

...

func adaptivePresentationStyle(for controller: UIPresentationController) -> UIModalPresentationStyle { 
    return .none 
} 

Antwort

2

Statt dieser

diamondViewController.preferredContentSize = CGSize(width: screenSize.width * 0.6, height: screenSize.height * 0.7) 

die Sie interessieren unten

0.123.
diamondViewController.view = CGRect(x: diamondViewController.view.frame.origin.x ,y: diamondViewController.view.frame.origin.y ,width: screenSize.width * 0.6, height: screenSize.height * 0.7) 

Wenn es nicht hilft dann lass mich wissen.

+1

Es funktioniert nicht auf iPhone 7 + – Khuong

0

Haben Sie versucht, das Werkzeug "Variieren für Merkmale" zu verwenden? Sie können abhängig von der Geräteausrichtung verschiedene Einschränkungen anwenden. Es befindet sich in der Nähe der unteren rechten Ecke im Storyboard neben den verschiedenen Constraint-Optionen.