2017-12-30 30 views
0

私は、ポップオーバービューコントローラ内のローディングバーの下にボタンを表示しようとしています。私はそれだけでUIProgressViewを表示することができます。私はスタックビューにUIProgressViewとUIButtonを配置し、それをポップオーバーの中央に表示するように取り組んでいます。ポップオーバーモーダルの中央スタックビュー

以下のコードを投稿しました。スタックビューにはボタンがありますが、デバッガに応じてx:-25 y:0にあります。私はself.view.centerの座標にスタックビューの中心座標を設定しようとしましたが、それは動作しませんでした。私が正しく設定していないものがありますか?

// Collection View #1 
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    let tv = VideoLibrary() // <- Collection View class 
    tv.videoSelectionDelegate = self 
    tv.modalPresentationStyle = .popover 
    tv.popoverPresentationController?.sourceView = self.view 
    present(tv, animated: true, completion: nil) 
} 

// VideoLibrary()/Collection View #2 
override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    let loadingView = LoadingVideoView() // <- view with stack view 
    loadingView.view.frame = self.view.frame 
    loadingView.modalPresentationStyle = .overCurrentContext 
    present(loadingView, animated: true, completion: nil) 
} 


// LoadingVideoView() 
var progressView: UIProgressView = { 
    let progress = UIProgressView(progressViewStyle: .default) 
    progress.progress = 0.5 
    return progress 
}() 
var blurView: UIVisualEffectView = { 
    let effect = UIBlurEffect(style: .extraLight) 
    let blur = UIVisualEffectView(effect: effect) 
    return blur 
}() 
var stack: UIStackView = { 
    let stack = UIStackView(frame: .zero) 
    stack.distribution = .equalSpacing 
    stack.axis = .vertical 
    stack.alignment = .center 
    stack.spacing = 20 
    return stack 
}() 
var cancelButton: UIButton = { 
    let button = UIButton(type: .roundedRect) 
    button.setTitle("Cancel", for: .normal) 
    button.addTarget(self, action: #selector(buttonPressed), for: .touchUpInside) 
    return button 
}() 

override func viewDidLoad() { 
    super.viewDidLoad() 
} 

override func viewWillAppear(_ animated: Bool) { 

    self.view.insertSubview(blurView, at: 0) 
    stack.addArrangedSubview(progressView) 
    stack.addArrangedSubview(cancelButton) 

    stack.translatesAutoresizingMaskIntoConstraints = false 
    cancelButton.translatesAutoresizingMaskIntoConstraints = false 
    progressView.translatesAutoresizingMaskIntoConstraints = false 

    stack.center = self.view.center 

    self.view.addSubview(stack) 
} 

enter image description here

答えて

0

周りの仕事はviewDidAppear(...)関数呼び出しでstack.center = self.view.centerを設定することです。 viewWillAppear(...)関数の最後では、中心値は(デバッガに応じて)等しくなりますが、viewDidAppear(...)が呼び出されると値が変更されます。私はこれらの2つの間に何が呼び出されているのか分からないが、今のところこれが機能する。