TNTutorialManager是一个易于实现的库,可以帮助您在iOS应用中创建交互式引导和教程!
完整分辨率GIF在此处。
下载"TNTutorialManager"文件夹并将文件添加到您的项目中。
仅Objective-C
将以下行添加到Podfile中
pod 'TNTutorialManager'
该库支持Objective-C和Swift
为了为特定ViewController添加教程,您只需要导入<TNTutorialManager.h>
(Objective-C)或import TNTutorialManager
(Swift),使ViewController遵从协议TNTutorialManagerDelegate
,并实现以下必需的方法
-(UIView *)tutorialMasterView;
-(BOOL)tutorialShouldCoverStatusBar;
-(void)tutorialWrapUp;
-(NSInteger)tutorialMaxIndex;
func tutorialMasterView() -> UIView!
func tutorialShouldCoverStatusBar() -> Bool
func tutorialWrapUp()
func tutorialMaxIndex() -> Int
方法tutorialMasterView
应该返回将作为子视图添加教程视图的UIView。
如果实现方法tutorialShouldCoverStatusBar
并返回YES
或true
,则会使管理器忽略tutorialMasterView
并创建自己的窗口,该窗口将显示在状态栏上方。
方法tutorialWrapUp
应该执行处理教程结束的代码,例如将tutorialManager
设置为nil并重新启用用户交互。
方法tutorialMaxIndex
应该返回教程的步骤数。
创建TNTutorialManager对象的简便方法是
Objective-C: tutorialManager = [[TNTutorialManager alloc] initWithDelegate:self];
Swift: let tm: TNTutorialManager = TNTutorialManager(delegate: self)
或者,也可以指定模糊强度,使用
Objective-C: - (instancetype)initWithDelegate:(id<TNTutorialManagerDelegate>)delegate blurFactor:(CGFloat)blurFactor;
Swift: let tm: TNTutorialManager = TNTutorialManager(delegate: self, blurFactor: 0.1)
其中blurFactor
的值介于0
和1
之间。默认值为0.1
。
另外的选项方法可以帮助您轻松创建交互式教程。
/**
Perform actions for a tutorial step, example: Tap a certain button.
*/
-(void)tutorialPerformAction:(NSInteger)index;
/**
Actions that need to be done before the highlight is done. Example, scroll to a certain UITableViewCell.
*/
-(void)tutorialPreHighlightAction:(NSInteger)index;
/**
This optional method should return the delay in seconds that the tutorialManager should wait before performing the next highlight, it is used in case there's a UI update that needs to be done.
*/
-(CGFloat)tutorialPreActionDelay:(NSUInteger)index;
/**
This optional method should return NO in case the tutorial shouldn't update for a certain index. Example: If the UI pushes a new UIViewController and you need to start a new tutorial from inside the new UIViewController.
*/
-(BOOL)tutorialWaitAfterAction:(NSInteger)index;
/**
Implementing this gives you the ability to force the user to tap on highlighted views instead of anywhere.
If there are no views highlighted in a certain tutorial step, this will be ignored, and the user will be able to tap anywhere.
*/
-(BOOL)tutorialAcceptTapsOnHighlightsOnly:(NSInteger)index;
/**
Methods used for building Tutorial UI.
*/
-(NSArray <UIView *> *)tutorialViewsToHighlight:(NSInteger)index;
-(NSArray <NSString *> *)tutorialTexts:(NSInteger)index;
-(NSArray <TNTutorialEdgeInsets *> *)tutorialViewsEdgeInsets:(NSInteger)index;
-(NSArray <NSNumber *> *)tutorialTextPositions:(NSInteger)index;
-(NSArray <UIFont *> *)tutorialTextFonts:(NSInteger)index;
-(NSArray <UIColor *> *)tutorialTextColors:(NSInteger)index;
-(UIColor *)tutorialTint:(NSInteger)index;
// Implement this method in case you wish to force the user to go through tutorial.
-(BOOL)tutorialHasSkipButton:(NSInteger)index;
// Default values are "Next" and "Skip". Implement those methods in case you wish to Localize your application or use different titles.
-(UIFont *)tutorialSkipButtonFont;
-(NSString *)tutorialSkipButtonTitle;
// Default value is [UIColor whiteColor].
-(UIColor *)tutorialButtonsColor;
// Identifier used in NSUserDefaults to save the progress of the tutorial for the specific view controllers. The default value is the class name of the delegate. Implement only in case the same UIViewController class will be used multiple times in your UI and need a different identifier for each time it is used.
-(NSString *)tutorialIdentifier;
/**
Perform actions for a tutorial step, example: Tap a certain button.
*/
func tutorialPerformAction(_ index: Int)
/**
Actions that need to be done before the highlight is done. Example, scroll to a certain UITableViewCell.
*/
func tutorialPreHighlightAction(_ index: Int)
/**
This optional method should return the delay in seconds that the tutorialManager should wait before performing
the next highlight, it is used in case there's a UI update that needs to be done.
*/
func tutorialPreActionDelay(_ index: UInt) -> CGFloat
/**
This optional method should return NO in case the tutorial shouldn't update for a certain index. Example: If
the UI pushes a new UIViewController and you need to start a new tutorial from inside the new UIViewController.
*/
func tutorialWait(afterAction index: Int) -> Bool
/**
Methods used for building Tutorial UI.
*/
func tutorialViews(toHighlight index: Int) -> [UIView]!
func tutorialTexts(_ index: Int) -> [String]!
func tutorialViewsEdgeInsets(_ index: Int) -> [TNTutorialEdgeInsets]!
func tutorialTextPositions(_ index: Int) -> [NSNumber]!
func tutorialTextFonts(_ index: Int) -> [UIFont]!
func tutorialTextColors(_ index: Int) -> [UIColor]!
func tutorialTint(_ index: Int) -> UIColor!
// Implement this method in case you wish to force the user to go through tutorial.
func tutorialHasSkipButton(_ index: Int) -> Bool
/**
Default values are "Next" and "Skip". Implement those methods in case you wish to Localize your application
or use different titles.
*/
func tutorialSkipButtonFont() -> UIFont!
func tutorialSkipButtonTitle() -> String!
// Default value is UIColor.white.
func tutorialButtonsColor() -> UIColor!
/**
Identifier used in NSUserDefaults to save the progress of the tutorial for the specific view controllers.
The default value is the class name of the delegate. Implement only in case the same UIViewController class
will be used multiple times in your UI and need a different identifier for each time it is used.
*/
func tutorialIdentifier() -> String!
仓库附带一个 Objective-C 示例项目,演示了如何实现管理器不同的功能。
请随意使用'TNTutorialManager'。不需要归属,但非常感谢。