Tôi có mã sau để hiển thị cửa sổ bật lên (hộp thoại) mà không có mũi tên, hoạt động tốt. Vấn đề duy nhất là, hộp thoại được hiển thị ở trên cùng bên trái (IPad). Tôi muốn căn giữa khung nhìn trên màn hình.cách căn giữa cửa sổ bật lên nhanh chóng
Điều gì sẽ thay đổi hoặc thêm vào mã sau của tôi? :
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)
}
}
bổ sung Infos
Theo quan điểm của tôi, được liên kết với viewController tôi thiết lập kích thước nghỉ như thế này:
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);
}
bạn có thể chỉ cần gửi ảnh chụp màn hình? Và tôi có thể biết nó có đầy đủ không? –
Cảm ơn bạn rất nhiều vì đã giúp đỡ. Tôi vừa thêm ảnh chụp màn hình và một số mã từ chế độ xem của mình. Màu xanh là nền. Trắng là cửa sổ của tôi. Mã bổ sung cho thấy, rằng tôi đặt kích thước preffered của cửa sổ bật lên. –
Thông thường, bạn nên sử dụng 'popoverLayoutMargins' trong trường hợp đó. Nhưng nhìn ở đây: http://stackoverflow.com/a/26632329/826716, nó bị hỏng trong iOS 8. – bteapot