人工智能技术杂谈程序员ios开发进阶

[程序员日记]iOS引导页LQIntroView

2017-04-17  本文已影响225人  KeyLiu7

引导页是app下载后打开的第一页,也决定着用户对软件的第一印象。在很多app中都是以多张图片通过滚动的方式介绍软件的内容,但形式过于单调。现今app中,有通过视频形式介绍(如keep等),都是在加强软件的吸引力。下面这个框架这是曾经一个项目中使用的框架,当然还是以图片为主,但加入了透明度渐变的效果,正价注重用户体验。先来看效果:

简述

使用

@property (nonatomic, strong) LQIntroView       *intro;

- (void)showCustomIntro {
    LQIntroPage *page1 = [LQIntroPage page];
    page1.bgImage = [UIImage imageNamed:@"欢迎页1"];

    LQIntroPage *page2 = [LQIntroPage page];
    page2.bgImage = [UIImage imageNamed:@"欢迎页2"];

    LQIntroPage *page3 = [LQIntroPage page];
    page3.bgImage = [UIImage imageNamed:@"欢迎页3"];

    _intro = [[LQIntroView alloc] initWithFrame:self.view.bounds andPages:@[page1,page2,page3]];

    [_intro setDelegate:self];
    [_intro showInView:self.view animateDuration:0.0];
}
if ([[LQIntroPageManager sharedInstance] disPlayTheIntroPage]) {
    [self showCustomIntro];
}

主要方法

单例类初始化

  + (instancetype)sharedInstance;

是否需要显示(安装后首次显示)

  - (BOOL)disPlayTheIntroPage;

设置大小及数组

- (id)initWithFrame:(CGRect)frame andPages:(NSArray *)pagesArray;

设置位置及出现动画时间

- (void)showInView:(UIView *)view animateDuration:(CGFloat)duration;

设置消失时间

- (void)hideWithFadeOutDuration:(CGFloat)duration;

初始化
+ (LQIntroPage *)page;

自定义初始化

+ (LQIntroPage *)pageWithCustomView:(UIView *)customV;

处理消失后要做的事

- (void)introDidFinish;

补充

兼容iPad和iPhone

因为在我的项目中要求iPad和iPhone兼容,即一个包同时支持两种设备,所以浅谈一下版本兼容和这个view的改法。在项目中,遇到同一个项目同时兼容iPad和iPhone时往往希望能够用最少量的代码完成。

我在做兼容时会定义两个宏

//适配iPhone尺寸
#define SIZE_SCALE_IPHONE6(x)   (x * ([UIScreen mainScreen].bounds.size.width / 375))
//适配iPad尺寸
#define SIZE_SCALE_IPADAIR(x)   (x * ([UIScreen mainScreen].bounds.size.width / 768))

在使用时如字体,定义大小时加上这个宏,如在Masory中:

make.top.equalTo(_loginBtn.mas_bottom).with.offset(SIZE_SCALE_IPHONE6(10));

一般情况下,会通过UI_USER_INTERFACE_IDIOM()判断当前设备是iPhone还是iPad,然后执行不同的代码。 其枚举类型如下:

typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
    UIUserInterfaceIdiomUnspecified = -1,
    UIUserInterfaceIdiomPhone NS_ENUM_AVAILABLE_IOS(3_2), // iPhone and iPod touch style UI
    UIUserInterfaceIdiomPad NS_ENUM_AVAILABLE_IOS(3_2), // iPad style UI
    UIUserInterfaceIdiomTV NS_ENUM_AVAILABLE_IOS(9_0), // Apple TV style UI
    UIUserInterfaceIdiomCarPlay NS_ENUM_AVAILABLE_IOS(9_0), // CarPlay style UI
};

LQIntroView中若要修改需手动修改

感谢查看,希望多多指正!
文章优先发表于:http://keyliu.com
转载请注明出处。

上一篇 下一篇

猜你喜欢

热点阅读