AwesomeIntroGuideView是一个iOSdrop-in类,它通过在现有UI上显示带有矩形、星形或环形切口的用户教练标记来实现。这种方法利用了您的实际UI作为用户入门过程的一部分。简单定义一个视图数组或字典(硬编码)或矩形(CGRect)以及相应的标题。更重要的是,您还可以定义一个入口显示图像,使用URL或本地资源引入视图,甚至您可以在引导图像上添加点击链接。例如,如果您定义了图像的URL - https://www.google.com,则用户会点击引导图像,您的应用程序将打开https://www.google.com。正如您可以想象的那样,您甚至可以提高应用程序的URL路径。
###CocoaPods
AwesomeIntroGuideView通过CocoaPods提供。为了安装它,只需将以下行添加到您的Podfile中:
pod 'AwesomeIntroGuideView'
或者,您可以直接将AwesomeIntroGuideView.h
和AwesomeIntroGuideView.m
源文件添加到项目中,另外,您还应该将MGJRouter添加到您的项目中。
在您的viewDidLoad或viewDidLayoutSubviews方法中创建一个新的AwesomeIntroGuideView实例,并传入一个视图数组或字典。
- (void)viewDidLayoutSubviews {
if (self.coachMarksShown == NO && self.introduceArray.count) {
[self.coachMarksView loadMarks:self.introduceArray];
[self.coachMarksView loadGuideImageUrl:introGuideImgUrl withPoint:(CGPoint){70,100} redirectURL:@"http://www.mogujie.com/" withFrequency:0];
[self.coachMarksView start];
}
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return 20;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
if (indexPath.row %5 == 0 && self.introduceArray.count <=3 && indexPath.row != 0) {
[self.introduceArray addObject:cell];
}
cell.backgroundColor = [UIColor colorWithRed:arc4random()%100/100. green:arc4random()%100/100. blue:arc4random()%100/100. alpha:arc4random()%100/100.];
return cell;
}
#pragma mark - Accessor
- (AwesomeIntroGuideView *)coachMarksView {
if (!_coachMarksView) {
_coachMarksView = [[AwesomeIntroGuideView alloc] initWithFrame:[UIScreen mainScreen].bounds];
}
return _coachMarksView;
}
如果您想控制每个教练标记的框架,可以使用下面的NSArray of NSDictionary
- (void)viewDidLoad {
[super viewDidLoad];
// ...
// Setup coach marks
NSArray *coachMarks = @[
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{0,0},{45,45}}],
@"caption": @"Helpful navigation menu"
@"shape": @"circle"
},
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{10.0f,56.0f},{300.0f,56.0f}}],
@"caption": @"Document your wedding by taking photos"
@"shape": @"square"
},
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{10.0f,119.0f},{300.0f,56.0f}}],
@"caption": @"Your wedding photo album"
},
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{10.0f,182.0f},{300.0f,56.0f}}],
@"caption": @"View and manage your friends & family"
},
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{10.0f,245.0f},{300.0f,56.0f}}],
@"caption": @"Invite friends to get more photos"
},
@{
@"rect": [NSValue valueWithCGRect:(CGRect){{0.0f,410.0f},{320.0f,50.0f}}],
@"caption": @"Keep your guests informed with your wedding details"
}
];
AwesomeIntroGuide *coachMarksView = [[AwesomeIntroGuide alloc] initWithFrame:self.view.bounds coachMarks:coachMarks];
[self.view addSubview:coachMarksView];
[coachMarksView start];
}
如果您想在特定的教练标记出现时执行某些操作,您可以定义AwesomeIntroGuideView的回调块
- (void)setUpCoachMarksViewCallBack {
self.coachMarksView = [[AwesomeIntroGuideView alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.coachMarksView.completionBlock = ^(AwesomeIntroGuideView *guideView){
NSLog(@"%@",guideView);
};
self.coachMarksView.willCompletionBlock = ^(AwesomeIntroGuideView *guideView){
NSLog(@"%@",guideView);
};
self.coachMarksView.didNavgateBlock = ^(AwesomeIntroGuideView *guideView, NSUInteger indedx) {
NSLog(@"%@",guideView);
};
self.coachMarksView.willNavgateBlock = ^(AwesomeIntroGuideView *guideView, NSUInteger indedx) {
NSLog(@"%@",guideView);
};
}
#pragma mark - Accessor
- (AwesomeIntroGuideView *)coachMarksView {
if (!_coachMarksView) {
_coachMarksView = [[AwesomeIntroGuideView alloc] initWithFrame:[UIScreen mainScreen].bounds];
_coachMarksView.loadType = AwesomeIntroLoad_Sync;
}
return _coachMarksView;
}
###更多细节
只需克隆存储库,查看我的代码
bupterAmbition,[email protected]
AwesomeIntroGuideView可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。