###前提・実現したいこと
yukiasai/Gecco/GeccoExample - GitHubを参考にウォークスルーを作ろうと試みました.
サンプルコードからstoryboardよりTabBarControllerを追加しました.(図1参照)
すると, ReccoExample.AnnotationViewControllerがTabBarControllerより下の階層にいってしまい, スポットライトをTabBar部分に反映することができませんでした.(図2参照)
スポットライト中にTabBarが押せてしまうことから, その間TabBarが押せないように以下の処理を加えました.
swift
1 if let tabArray = self.tabBarController?.tabBar.items { 2 tabArray[1].isEnabled = false 3 }
しかし, 押せるように以下の箇所で,
tabArray[1].isEnabled = true
と変更したかったのですが, ViewControllerでのselfの値(図3参照)を受け渡すことができず, nilが出てしまい処理を施すことができません.
(StoryboardID : ViewController 追加)
swift
1 case 4: 2 let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ViewController") as! C 3 if let tabArray = viewController.tabBarController?.tabBar.items { 4 tabArray[1].isEnabled = true 5 } 6 dismiss(animated: true, completion: nil)
簡潔にまとめると,
GeccoはTabBarに反映させることはできないのか?
もしできない場合は,
スポットライト中にTabBarが押せなくなるようにし, スポットライトが終えたらTabBarが押せるようにしたい.
GeccoがTabBarに反映させることができるのであればそれにこしたことはありません.
ご教授のほどよろしくお願いいたします.
###該当のソースコード
swift
1import UIKit 2 3class ViewController: UIViewController { 4 5 override func viewDidLoad() { 6 super.viewDidLoad() 7 } 8 9 override func viewDidAppear(_ animated: Bool) { 10 super.viewDidAppear(animated) 11 } 12 13 @IBAction func buttonPressed(_ sender: AnyObject) { 14 presentAnnotation() 15 } 16 17 func presentAnnotation() { 18 if let tabArray = self.tabBarController?.tabBar.items { 19 tabArray[1].isEnabled = false 20 } 21 let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Annotation") as! AnnotationViewController 22 viewController.alpha = 0.5 23 present(viewController, animated: true, completion: nil) 24 } 25}
swift
1import UIKit 2import Gecco 3 4class AnnotationViewController: SpotlightViewController { 5 6 @IBOutlet var annotationViews: [UIView]! 7 8 var stepIndex: Int = 0 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 delegate = self 14 } 15 16 func next(_ labelAnimated: Bool) { 17 updateAnnotationView(labelAnimated) 18 19 let screenSize = UIScreen.main.bounds.size 20 switch stepIndex { 21 case 0: 22 spotlightView.appear(Spotlight.Oval(center: CGPoint(x: screenSize.width - 26, y: 42), diameter: 50)) 23 case 1: 24 spotlightView.move(Spotlight.Oval(center: CGPoint(x: screenSize.width - 75, y: 42), diameter: 50)) 25 case 2: 26 spotlightView.move(Spotlight.RoundedRect(center: CGPoint(x: screenSize.width / 2, y: 42), size: CGSize(width: 120, height: 40), cornerRadius: 6), moveType: .disappear) 27 case 3: 28 spotlightView.move(Spotlight.Oval(center: CGPoint(x: screenSize.width / 2, y: 200), diameter: 220), moveType: .disappear) 29 case 4: 30 // ここで, isEnabled = true にしようとした 31 dismiss(animated: true, completion: nil) 32 default: 33 break 34 } 35 36 stepIndex += 1 37 } 38 39 func updateAnnotationView(_ animated: Bool) { 40 annotationViews.enumerated().forEach { index, view in 41 UIView.animate(withDuration: animated ? 0.25 : 0) { 42 view.alpha = index == self.stepIndex ? 1 : 0 43 } 44 } 45 } 46} 47 48extension AnnotationViewController: SpotlightViewControllerDelegate { 49 func spotlightViewControllerWillPresent(_ viewController: SpotlightViewController, animated: Bool) { 50 next(false) 51 } 52 53 func spotlightViewControllerTapped(_ viewController: SpotlightViewController, isInsideSpotlight: Bool) { 54 next(true) 55 } 56 57 func spotlightViewControllerWillDismiss(_ viewController: SpotlightViewController, animated: Bool) { 58 spotlightView.disappear() 59 } 60}
###補足情報(言語/FW/ツール等のバージョンなど)
図1 Storyboard(Tab Bar Controller 追加のみ)
図2 階層
図3 dump(self.tabBarController?.tabBar.items)での処理結果[ViewController.swift]
あなたの回答
tips
プレビュー