Tôi muốn hiển thị Chế độ xem - PresentedView
qua chế độ xem khác - Background View
bằng iOS 7. Trong ứng dụng của tôi, tôi đang sử dụng UITabBArController
, vì vậy khi chạy tôi không biết chế độ xem nào sẽ là chế độ xem nền (có thể là bất kỳ mục nào trong tab tab). Dưới đây là cấu trúc:UIModalPresentationStyle.CurrentContext Swift iOS 7
UITabBarController
---> TabItem1 - FirstUIViewController
---> TabItem2 - SecondUIViewController
---> TabItem3 - ThirdUIViewController
Cần một cái gì đó Như thế này:
Khi tải ứng dụng, tôi đang trên TabItem1 - FirstUIViewController
. Khi tôi nhấp vào TabItem3
, tôi muốn ThirdUIViewController
xuất hiện trên Top trên FirstUIViewController
và 'FirstUIViewController' sẽ xuất hiện ở chế độ nền mà không có tương tác người dùng nào được bật.
Những gì tôi đã làm như vậy cho đến nay:
Từ,
UIViewControllers
được thêm vào nhưRelationship Controllers
xuất hiện nhưTabBar Item
trong `UITabBarController, tôi đã thêm một segue từ tabbarcontroller để ThridViewController.Changed PresentationStyle cho Segue này để UIModalPresentationStyle.CurrentContext và đã làm dưới đây sửa đổi
func `viewDidLoad()` { super.viewDidLoad() self.performSegue("identifier", sender: self) }
Không có gì xảy ra và tôi chỉ thấy 'ThridViewController' với nền trắng
Tôi đã thử phương pháp mã hóa thủ công:
func `viewDidLoad()` { super.viewDidLoad() let overlayController:UIThirdViewController = UIThirdViewController() //This controller has a view added on top of it, which covers top half screen only overlayController.modalPresentationStyle = UIModalPresentationStyle.CurrentContext self.presentViewController(overlayController, animated: true, completion: nil) }
Không thay đổi. Chế độ xem mới sẽ ghi đè chế độ xem ưu tiên. nếu tôi thêm overlayController.view.backgroundColor = UIColor.clearColor()
này, tôi thấy một nửa màn hình màu đen và một nửa chứa cái nhìn mới của tôi
Vấn đề điểm:
- tôi nên viết mã để khởi tạo ở đâu/gọi ThirdViewController xuất hiện trên đầu trang của chế độ xem hiện tại?
- Cách khắc phục sự cố màn hình đen và làm cho nó hoạt động trên iOS 7?
Tôi đang sử dụng Xcode 7 và chạy trên iOS7. Hãy giúp tôi. Đoạn mã làm việc sẽ được đánh giá cao. Không đăng các bài đăng tràn ngăn xếp khác làm câu trả lời, trừ khi mã hoạt động & bạn đã tự thử.
UPDATE: - Với phương pháp này, tôi nhận được một màn hình màu đen
class TabBarViewController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
func tabBarController(tabBarController: UITabBarController, shouldSelectViewController viewController: UIViewController) -> Bool {
let switchController:UIViewController = SwitchViewController()
self.presentingViewController?.modalPresentationStyle = UIModalPresentationStyle.CurrentContext
self.presentingViewController?.view.backgroundColor = UIColor.clearColor()
self.presentViewController(switchController, animated: true, completion: nil)
return false
}
}
Liệu nó làm việc trên iOS 7? – Sategroup
Có, tôi tin rằng các API này đã có từ iOS 5, bằng cách xem xét hỗ trợ phiên bản cho addChildViewController. – bobics