Mam następujący kod, aby wyświetlić widok na popover (okno dialogowe) bez strzałki, która działa poprawnie. Jedynym problemem jest to, że okno dialogowe jest wyświetlane w lewym górnym rogu (IPad). Chciałbym wyśrodkować widok na ekranie.Jak wyśrodkować wyskakujący ekran w trybie szybkim
Co zmienić lub dodać w poniższym kodzie? :
func show_help(){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewControllerWithIdentifier("Help") as! UIViewController
controller.modalPresentationStyle = UIModalPresentationStyle.Popover
let popoverPresentationController = controller.popoverPresentationController
// result is an optional (but should not be nil if modalPresentationStyle is popover)
if let _popoverPresentationController = popoverPresentationController {
// set the view from which to pop up
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirection.allZeros;
// present (id iPhone it is a modal automatic full screen)
self.presentViewController(controller, animated: true, completion: nil)
}
}
Dodatkowe Informacje
Moim zdaniem, która jest związana z moim viewcontroller ustawić preferowany rozmiar takiego:
override func viewDidLoad() {
let dialogheigth:CGFloat = self.view.frame.height * 0.5;
let dialogwidth:CGFloat = self.view.frame.width * 0.5;
self.preferredContentSize = CGSizeMake(dialogwidth,dialogheigth);
}
można po prostu opublikować zrzut ekranu? Czy mogę wiedzieć, że w pełni się pojawia? –
Wielkie dzięki za pomoc. Właśnie dodałem zrzut ekranu i trochę kodu z mojego widoku. Niebieski kolor to tło. Biały to mój popover. Dodatkowy kod pokazuje, że ustawiłem preferowany rozmiar popover. –
Zwykle w takim przypadku powinieneś używać 'popoverLayoutMargins'. Ale spójrz tutaj: http://stackoverflow.com/a/26632329/826716, jest uszkodzony w iOS 8. – bteapot