7

Tôi đang cố gắng tạo một cửa sổ bật lên giống như phiên bản 214 trong WWDC 2014.iOS 8: Áp dụng UIVisualEffectView với hiệu ứng Blur cho PopOver phương thức ở chế độ thu gọn

Vì vậy, tôi bắt đầu xây dựng ứng dụng của tôi bằng cách sử dụng IB có hai quan điểm nối với nhau bằng một "hiện tại Như Popover" segue, như vậy:

enter image description here Quan điểm popover chứa một cái nhìn văn bản đầy SuperView của nó, với những điều sau hạn chế: enter image description here

để hỗ trợ các phương thức popover đoạn mã sau:

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle { 
    return .OverFullScreen 
} 

func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { 

    let navigationController = UINavigationController(rootViewController: controller.presentedViewController) 
    controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true) 

    return navigationController 
} 

này đã cho tôi lại sau sult: enter image description here

Sau đó, tôi đã cố gắng thêm UIVisualEffectView với hiệu ứng mờ. Lúc đầu, tôi chỉ đơn giản là thêm một khung nhìn con vào khung nhìn trình điều khiển được trình bày và sau khi kiểm tra Phân cấp Xem, tôi nhận ra rằng chế độ xem hiệu ứng của tôi thực tế ở trên đầu chế độ xem văn bản, nhưng chế độ xem văn bản của tôi được đặt chính xác. Vì vậy, tôi đã cố gắng insertSubview: atIndex: Phương pháp như ví dụ:

func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? { 

    let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView 
    effectView.setTranslatesAutoresizingMaskIntoConstraints(false) 
    controller.presentedViewController.view.insertSubview(effectView, atIndex: 0) 

    let viewList : [String : UIView] = ["effectView" : effectView] 

    let navigationController = UINavigationController(rootViewController: controller.presentedViewController) 
    controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true) 


    controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[effectView]|", options: nil, metrics: nil, views: viewList)) 

    controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[effectView]|", options: nil, metrics: nil, views: viewList)) 

    return navigationController 
} 

Nhưng tôi vẫn không thể trình bày quan điểm văn bản quy định tại các IB: enter image description here

Qua Xem Hierarchy Tôi có thể thấy rằng văn bản của tôi xem, bằng cách nào đó, đang được di chuyển bên dưới thanh điều hướng khi tôi chèn UIVisualEffectView vào chỉ mục 0.

Bất kỳ suy nghĩ nào về cách lập trình hiệu ứng mờ bên dưới văn bản mà không làm cho nó biến mất/di chuyển bên dưới thanh điều hướng?

Chúc mừng

Trả lời

0

Chức năng này có giúp bạn không?

view.insertSubview(view: effectView, belowSubview: label) 
Các vấn đề liên quan