2017-01-06 4 views
2

ビデオをスクロールし続ける:Videoはビデオを持っている:覗くとポップ(3Dタッチ)した後、背景には、バグの

私はUITableViewCellsとの定期的なテーブルビューを持っています。メッセージのように見えます。私は別のビューコントローラOperationDetailsViewControllerを持っています。プレビューを表示するには

// need that dict for 3D touch 
var dict_previwingControllers_cellIsKey = [UITableViewCell: UIViewControllerPreviewing]() 

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { 

    // setup peek and pop (register proper view) 
    if traitCollection.forceTouchCapability == .available, let cellForChat = cell as? OperationsSingleCell { 
     let previewingController = registerForPreviewing(with: self, sourceView: cellForChat.viewTextBG) 
     dict_previwingControllers_cellIsKey[cell] = previewingController // remember because we need to unregister 
    } 
} 

func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { 
    // setup peek and pop (unregister) 
    if traitCollection.forceTouchCapability == .available { 
     if let previwingController = dict_previwingControllers_cellIsKey[cell] { 
      unregisterForPreviewing(withContext: previwingController) 
     } 
    } 
} 

ユーザーがメッセージの背景にタップしたときに、私は、この持っている:私はこれを持ってテーブルビューのデリゲートで

/// Create a previewing view controller to be shown at "Peek". 
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { 
    // Obtain cell by previewing context 
    guard let cell = (dict_previwingControllers_cellIsKey as NSDictionary).allKeys(for: previewingContext).first as? OperationsSingleCell else {return nil} 
//  guard let indexPath = tableViewMain.indexPathForRow(at: location), 
//   let cell = tableViewMain.cellForRow(at: indexPath) as? OperationsSingleCell else { return nil } 


    guard let operationDetailsVC = storyboard?.instantiateViewController(withIdentifier: "OperationDetailsVC") as? OperationDetailsVC else {return nil} 
    // custom properties 
    operationDetailsVC.dbOrder = cell.dbOrder 
    operationDetailsVC.navigationControllerOfParentVC = navigationController 
    // need to load view so we will know content size 
    operationDetailsVC.view.reloadInputViews() 

    let contentHeight = operationDetailsVC.scrollViewMain.contentSize.height 

    /* 
    Set the height of the preview by setting the preferred content size of the detail view controller. 
    Width should be zero, because it's not used in portrait. 
    */ 
    operationDetailsVC.preferredContentSize = CGSize(width: 0.0, height: contentHeight) 

    // Set the source rect to the cell frame, so surrounding elements are blurred. 
    previewingContext.sourceRect = cell.viewTextBG.bounds 

    return operationDetailsVC 
} 

/// Present the view controller for the "Pop" action. 
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) { 
    // Reuse the "Peek" view controller for presentation. 
    show(viewControllerToCommit, sender: self) 
} 

をしかし、ユーザーが使用している場合、3Dタッチの背景には上のようにスクロールし続けますビデオ

iMessageアプリケーションでは起こりませんので、それは起こりません

+0

あなたがテーブルビューにメッセージをタップしたときに、ジェスチャーrecognizorはテーブルビューにあります。あなたが指を離さなかったので、スワイプはテーブルビューによっても認識されます。指を離すと、3Dタッチビューが画面に表示されるので、テーブルビューはスワイプできません。 テーブルビューのスクロールを無効にすることができます。 – WeiJay

+0

はい、テーブルビュー認識機能が現時点でアクティブなので、理解していますが、iMessageアプリケーションでそのようなことは起こりません。 –

+0

willDisplayとtrueに設定するとtableviewをfalseに設定しようとすることができますWhen EndDisplay – WeiJay

答えて

0

私はデフォルトのtableViewで試してみましたが、状況はありません。つまり、私の3dViewのtableViewセルに触れると、detailViewがポップアップし、背景ビュー(tableView)はスクロールできません。

また、すべてのセルをプレビューするために登録する必要はありません。一度にテーブルビューセル全体を登録するだけで済みます。私の意見で

class ViewController: UIViewController { 

    @IBOutlet weak var tableView: UITableView! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     if traitCollection.forceTouchCapability == .available { 
      registerForPreviewing(with: self, sourceView: tableView) 
     } 
    } 

} 

extension ViewController: UITableViewDataSource, UITableViewDelegate { 
    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 20 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) 
     cell.textLabel?.text = "Hello World" 
     return cell 
    } 
} 

PreviewDelegate

extension ViewController: UIViewControllerPreviewingDelegate { 
    func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { 
     guard let indexPath = tableView.indexPathForRow(at: location) else { return nil } 
     guard let cell = tableView.cellForRow(at: indexPath) else { return nil } 

     guard let operationDetailsVC = storyboard?.instantiateViewController(withIdentifier: "OperationDetailsVC") as? OperationDetailsVC else { return nil } 

     operationDetailsVC.preferredContentSize = CGSize(width: 0, height: 300) 
     previewingContext.sourceRect = cell.frame 

     // You can decide to return a viewController or nil for certain cell 
     return operationDetailsVC 

    } 

    func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) { 
     show(viewControllerToCommit, sender: self) 
    } 
} 
+0

と書くことができます。角が丸くならないので、角の丸いテキストの背景だけを強調表示することはできません –

関連する問題