• iOS App引导页功能实现


    一、写作原因

          以前都没有想着来写点东西,今天遇到件事情让我决定每次还是要做记录。因为以前自己可以轻松的完成pod spec的配置,但是今天在做的时候还是忘了遇到了很多坑。pod spec配置遇到的坑不在这里写,后面会单独写一点,但是内容不会太多。一是方便别人,二是方便自己。

        第一次来发帖,写的不对的地方,请大神指出。我一定好好的努力修改并向大家学习,但是还是不太喜欢一惯的喷子。就像大家说的经典一样`close your mouth show me your code`,英文不好如果错了,大家见谅。

        因为我是鼓足勇气的来写的,是想来提升的,不是来听大家一味的喷,而不是告诉我如何提高这样是让人crash的。

    Demo下载地址,先上github地址,怕到后面给忘记了。如果可以请给star我,谢谢。

    二、XLJNewFeture实现原理

        引导页的功能分析,其它就是一个scrollview加上一个pagecontrol最后加上一个按钮,按钮的点击事件是需要到app程序的首页。实现这个功能的方法有很多,此文只是介绍collview 来实现这个功能。

      我实现的思路是这样的,最开始设计是这样的写一个类继承自UICollectionView,然后写一个UICollectionViewCell的类来实现具体的布局。但是写完之后在AppDelegate 中设置 self.windown.rootViewController的时候总是crash掉,后来查到的原因忘记了。请知道的朋友告知,我好更新上来,感激不尽。现在使用的是直接继承自UIViewController,在UIViewController上放一个UICollectionView,再由UICollectionViewLayout布局,然后自定义一个UICollectionViewCell,最后才是button的问题。

    XLJNewFeature新特性

    ★★★"iOS App新特性"★★★

    支持pod导入

    pod 'XLJNewFeature', '~> 1.0.0'

    如果发现pod search XLJNewFeature 搜索出来的不是最新版本,需要在终端执行cd转换文件路径命令退回到desktop,然后执行pod setup命令更新本地spec缓存(可能需要几分钟),然后再搜索就可以了。

    接口代码:

    /**

    *  初始化

    *  @param array      传入一个数组

    *  @param buttonSize  按钮的宽度和高度

    *  @param buttonTitle 按钮显示的文字

    *  @param imageName  按钮的图片

    *@param titleColor  按钮文字的颜色

    *  @param startHeight 按钮的Y的比率

    *  @param controller  按钮点击跳转的界面

    *@return

    */

    - (instancetype)initWithNSArray:(NSMutableArray *)array withButtonSize:(CGSize)buttonSize withButtonTitle:(NSString *)buttonTitle withButtonImage:(NSString *)imageName withButtonTitleColor:(UIColor *)titleColor withButtonHeight:(CGFloat)startHeight withViewController:(UIViewController *)controller;

    在AppDelegate中导入"XLJNewFetureController.h"

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    ViewController *homeVC = [[ViewController alloc] init];

    XLJNewFetureController *newVC = [[XLJNewFetureController alloc] initWithNSArray:self.mArray withButtonSize:CGSizeMake(120, 80) withButtonTitle:@"开启旅行" withButtonImage:@"functionGuideBt1" withButtonTitleColor:[UIColor orangeColor] withButtonHeight:0.87 withViewController:homeVC];

    self.window.rootViewController = newVC;

    [self.window makeKeyAndVisible];

    return YES;

    }

    其中判断当前的图片是否是最后一页,是通过indexPath.row与self.mArray.cout-1来判断的。由于是最后一页,button的hidden = NO,否则就是YES.

    - (void)setCurrentPageIndex:(NSInteger)currentPage lastPageIndex:(NSInteger)lastIndex

    {

    if (currentPage == lastIndex) {

    self.startButton.hidden = NO;

    }else{

    self.contentView addSubview:self.startButton];

    [self.startButton.hidden = YES;

    }

    }

    PS:

    1.如果有的建议可以email:marlonxlj@163.com,谢谢你的关心,是我最大动力,请star一下哦。

    2.原创作品,转载请说明出处。

    效果图


    引导页效果图
  • 相关阅读:
    java并发包——Semaphore(信号量)
    cnblogs
    linux下安装python3及对应的pip环境
    Swing实现AES加密&解密工具升级
    Netty——知识点总结
    RPC——看这一篇就…显然不够
    ORM——Mybatis
    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException问题解决
    设计模式分类及常用设计模式
    Java 语言特性【四】——其他
  • 原文地址:https://www.cnblogs.com/marlonxlj/p/5962540.html
Copyright © 2020-2023  润新知