단순하고 세련된 튜토리얼 라이브러리, Instructions

8587 단어 SwiftInstructions

사용 중인 라이브러리


Instructions
https://github.com/ephread/Instructions
tableView처럼 직관적으로 사용하기 편리합니다.
ViewController.swift
class ViewController: UIViewController{

//手取り早くstoryboardで設置して紐付けといてください。
    @IBOutlet weak var startButton: UIButton!
    let coachMarksController = CoachMarksController()
    //pointOfInterestが指し示されます。スポットライトが当たるみたいに
    private var pointOfInterest:UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.coachMarksController.dataSource = self
        self.pointOfInterest = self.startButton 

    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated) 
        self.coachMarksController.start(in: .currentWindow(of: self))
    }
}

extension ViewController:CoachMarksControllerDataSource, CoachMarksControllerDelegate{
    func numberOfCoachMarks(for coachMarksController: CoachMarksController) -> Int {
//表示するスポットライトの数。チュートリアルの数。
        return 1
    }

    func coachMarksController(_ coachMarksController: CoachMarksController,
                                  coachMarkAt index: Int) -> CoachMark {
//指し示す場所を決める。 今回はpointOfInterestすなわちButtonga指し示される
        return coachMarksController.helper.makeCoachMark(for: pointOfInterest)
    }


//tableview でいうreturn cellに似てるのかなってイメージ。表示するチュートリアルメッセージなどがいじれる
    func coachMarksController(_ coachMarksController: CoachMarksController, coachMarkViewsAt index: Int, madeFrom coachMark: CoachMark) -> (bodyView: CoachMarkBodyView, arrowView: CoachMarkArrowView?) {
        let coachViews = coachMarksController.helper.makeDefaultCoachViews(withArrow: true, withNextText: true, arrowOrientation: coachMark.arrowOrientation)
        coachViews.bodyView.hintLabel.text = "チュートリアルメッセージです!"
        coachViews.bodyView.nextLabel.text = "OK"
        return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
    }
}


주의사항


github의 예시 코드와 다른 점
self.coachMarksController.start(in: .window(over: self))
이 코드로 움직여야 하는데 ERROR을 만났어요.
[ERROR] The overlay view added to the window has empty bounds, Instructions will stop.
https://github.com/ephread/Instructions/issues/231
여기 열거했습니다.아래와 같이 수정하고 순조롭게 움직였습니다!
self.coachMarksController.start(in: .currentWindow(of: self))

좋은 웹페이지 즐겨찾기