2016-09-07 5 views
0

私は現在、自分の小さなアプリで3Dタッチを実装しようとしています。アプリケーションは学校プランナーのようなものなので、メインビューのControllerはUITableViewController、テーブルビューにはいくつかのレッスンがあり、そのうちの1つをクリックするとSegueが表示され、アクティブView Controllerが 'DetailedViewController '.swift。これまでのところすべてが機能します。しかし、今私は、ユーザーが特定のレッスンのプレビューを得るために「レッスン」を難しく押すことができるように、3Dタッチを実装しようとしています。私の最初の試みは、ストーリーボードのセグのチェックマークを設定することでした。実際にプレビューが表示されましたが、プレビューの下にいくつかのアクションを追加して、タイトルを付けたいと思います。だから私はUIViewControllerPreviewingDelegateプロトコルを実装し、私のカスタム関数を作成しようとしました。3Dタッチ機能を正しくオーバーライドするにはどうすればいいですか?

しかしその後、私はどのように続行するのか分かりません。

マイ機能:

override func viewDidLoad() { 
    super.viewDidLoad() 
    self.navigationItem.leftBarButtonItem = self.editButtonItem() 
    // .... Some other irrelevant stuff 
    registerForPreviewingWithDelegate(self, sourceView: view) 
} 

func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? { 
    if let indexPath = tableView.indexPathForRowAtPoint(location) { 
     //This will show the cell clearly and blur the rest of the screen for our peek. 
     previewingContext.sourceRect = tableView.rectForRowAtIndexPath(indexPath) 
    } 
    return nil 
} 

func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) { 
    presentViewController(viewControllerToCommit, animated: true, completion: nil) 
} 

override func previewActionItems() -> [UIPreviewActionItem] { 
    print("previewActionItems") 
    let action = UIPreviewAction(title: "Press Me!", style: .Default) { (action, viewController) in 
     print("I believe I can fly") 
    } 
    return [UIPreviewAction](arrayLiteral: action) 
} 

そして、私のクラス:

初期ビューコントローラがMainTableViewControllerです。上記のすべての関数がこのクラスに記述されています。

さらに詳細なビューコントローラは、DetailedViewControllerです。

ありがとうございました!

+2

それは、うん、私は知っている – Wain

+0

話題にWWDCのセッション(複数可)を見るとよいでしょう...しかし、私はちょうど今のxD – dv02

+0

あなたはこれを見たいと思うかもしれません私の質問への答えを取得したいです[チュートリアル](http://code.tutsplus.com/tutorials/ios-9-an-introduction-to-3d-touch--cms-25115)。あなたは、あなたの質問に対するプログラマティックとストーリーボードの両方の解決策を見つけることができます。 – Ayazmon

答えて

0
override var previewActionItems: [UIPreviewActionItem] { 

    let action1 = UIPreviewActionGroup(title: NSLocalizedString("action1", comment: "action1"), style: .default, actions: someAction) 

    let action2 = UIPreviewAction(title: "action2", style: .default) {[unowned self] (action, viewController) in 
     print("action2") 
    } 

    return [action1, action2] 
} 
関連する問題