Swift5 引导页

作者: long弟弟 | 来源:发表于2021-03-19 00:27 被阅读0次

Swift5.x版本,ABI(应用程序二进制接口)终于稳定,也是时候从OC转Swift了😁

熟悉的OC框架,有的可以桥接继续使用,如AFNetworking、MJRefresh、YYKit等;也有对Swift不友好的,如KSGuaidView

分析原因是Swift不支持宏定义,而KSGuaidView中使用宏定义单例manager

#ifndef KSGuaidManager
#define KSGuaidManager [KSGuaidViewManager manager]

@implementation KSGuaidViewManager

static KSGuaidViewManager* _manager = nil;
static dispatch_once_t _onceToken;

+ (instancetype)manager{
    dispatch_once(&_onceToken, ^{
        _manager = [[super allocWithZone:NULL] init];
    });
    return _manager;
}
...

所以仿照KSGuaidView思路写了一个Swift版的WelcomePage,方便转Swift的童鞋使用。同样可以实现两种展示方式

WelcomePage1.gif
WelcomePage2.gif

主要侵入代码:

var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        loadWelcomePage()
        return true
    }
    
    private func loadWelcomePage() {
        //显示要欢迎的图片数组
        GuideManager.share.images = [UIImage(named: "start_page1")!, UIImage(named: "start_page2")!, UIImage(named: "start_page3")!]
        //显示“点击体验”按钮,不赋值就是滚动进入应用
        GuideManager.share.enterImage = UIImage(named: "start_enter")
        //默认是展示UIPageControl控件,不需要展示打开下行注释即可
        //GuideManager.share.isShowPageControl = false
        GuideManager.share.checkVersion()
    }

主要代码:

    func showGuideView(_ currentVersion: String) {
        guideWindow = UIWindow(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
        guideWindow?.windowLevel = .statusBar
        
        let rootVC = GuideViewController()
        rootVC.images = images
        rootVC.enterImage = enterImage
        rootVC.isShowPageControl = isShowPageControl
        rootVC.dismissClosure = { [weak self] in
            try? currentVersion.write(toFile: VersionPath, atomically: true, encoding: .utf8)
            self?.dismissGuideView()
        }
        guideWindow?.rootViewController = rootVC
        guideWindow?.makeKeyAndVisible()
    }

将WelcomePage文件夹拖入项目,AppDelegate.swfit中配置即可

  • 特别说明:
    需要删除SceneDelegate.swift及相关配置代码才能正常显示欢迎页。

完整Demo

相关文章

  • Swift5 引导页

    Swift5.x版本,ABI(应用程序二进制接口)终于稳定,也是时候从OC转Swift了? 熟悉的OC框架,有的可...

  • Swift - 页控件(UIPageControl)的用法

    (本文代码已升级至Swift5) 使用页控件可以用来展示多个桌面。比如很多应用第一次登陆时会有个引导页(或叫做指导...

  • 引导页

    // // ViewController.m // 引导页_课堂练习 // // Created by 张羽婷 o...

  • 引导页

    引导页是用户第一次使用app时,引导用户使用的页面,这个界面通常加载到进入界面的上面。我这个引导页是一个View,...

  • 引导页

    AppDelegate.m #import "AppDelegate.h" #import "ViewContro...

  • 引导页

    判断版本号 引导页界面 点击方法

  • 引导页

    引导页 引导页是在程序第一次安装的时候呈现出来的画面. 新建一个.pch.用于做程序中的声明.声明这几个变量 在 ...

  • 引导页

    sharedPreferences = getSharedPreferences("ues", MODE_PRIV...

  • 引导页

    引导页设计 一般不会超过5页。作用:让用户了解产品价值和功能,引导用户更快进入使用环境。 按照功能分类: 1.功能...

  • 引导页

    第一种方法: 通过点击按键的方式进入应用### 该方法需要两个视图控制器,一个用来创建引导页的滚动视图,另一个创建...

网友评论

    本文标题:Swift5 引导页

    本文链接:https://www.haomeiwen.com/subject/gphgfltx.html