- 一直以为这种事分分钟钟,结果就是要踩点坑才知道好坏
LaunchImage
-
iOS11现在项目的General设置:
这个简单吧,在Assets --> 点击+号选择 --> AppIcons & LaunchImages --> New iOS Launch Image,如下图:
- 在LaunchImage的右边栏选择属性 ---> 选择iOS7和iOS8以后的竖屏的,如下图:
- 到了这一步,贴尺寸
- 640*960 (4/4s) 2x位置
- 640*1136 (5/5s/5c/SE) R4位置
- 750*1334 (6, 7) R4.7位置
- 1242*2208 (6 plus, 7Plus) R5.5位置
- 1125x2436(iPhoneX) iPhoneX位置
- 我贴贴贴.....贴不上啊.....莫非尺寸错了,UI给的是1242*2208贴不上,为缩放先看看其他的能行不
- 打开预览图片--> 点击工具 --> 调整大小,如下图:
- 要去掉比例缩放,因为不是等比的,如下图:
- 又开始贴贴贴.....还是不行....看了一下图片的后缀我的眼泪掉下来,真心没注意居然是jpg的图片,LaunchImage只支持PNG啊
- 所以又改了, 图片预览 --> 文件 --> 导出--> 选择PNG,如下图:
- 好了,这才贴上,Launch Screen File为空.然后项目--> General --> App Icons and Launch Images -- > Launch Images Source选择LaunchImage就可以了,如下图:
- 让我们见证惊喜的时刻:
- 这尼玛还是前面的LaunchImage是为啥?还是这黑屏是什么鬼?点击项目还能这样:
- 我感觉自己被蠢哭了,想起xcode8使用xib的时候那个坑爹的缓存,这缓存太严重了吧,clean一下:
- 结果黑屏还是存在,一看就是LaunchImage尺寸不对,可才知道原来可以这样缩小一个应用的尺寸,重新检查尺寸贴上就ok,终于ok了.
AppIcon
- 额,想说忽然发现和LaunchImage差不多啊,就就是新建AppIcon照着有的尺寸x倍数修图就可以了
引导页
- 尺寸需要最大的: 750x1334pt
- 引导页主要更具UI给的图我们在程序中修一下图片就可以,我直接上代码吧,不能直接使用哦!有自己的宏和控制器在里面:
#import "LXKGuideViewVC.h"
#import "B1_LXKLoginVC.h"
#import "LXKNavigationController.h"
// 分页控件的高度
static const NSUInteger kPageControlHeight = 120;
@interface LXKGuideViewVC () <UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *guideViewScrollView; //引导页的滚动视图
@property (nonatomic, strong) UIPageControl *pageControl; //创建分页控件 监控当前页面和使页面一页页的翻动
@property (nonatomic, copy) NSArray *imageNameArray; // 引导页图片的名字
@end
@implementation LXKGuideViewVC
#pragma mark - Lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.guideViewScrollView];
[self.view addSubview:self.pageControl];
[self createGuideView];
}
#pragma mark - Custom Accessors
- (UIScrollView *)guideViewScrollView {
if (!_guideViewScrollView) {
_guideViewScrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_guideViewScrollView.bounces = NO;
_guideViewScrollView.showsHorizontalScrollIndicator = NO;
// 打开分页控件
_guideViewScrollView.pagingEnabled = YES;
_guideViewScrollView.delegate = self;
}
return _guideViewScrollView;
}
- (NSArray *)imageNameArray {
if (!_imageNameArray) {
_imageNameArray = @[@"GuideView1",@"GuideView2",@"GuideView3"];
}
return _imageNameArray;
}
- (UIPageControl *)pageControl {
if (_pageControl) {
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, SCREENHEIGHT - kPageControlHeight, SCREENWIDTH, kPageControlHeight)];
}
return _pageControl;
}
#pragma mark - privateMethod
- (void)createGuideView {
self.guideViewScrollView.contentSize = CGSizeMake(SCREENWIDTH * self.imageNameArray.count + SCREENWIDTH, SCREENHEIGHT);
// 循环创建图片
for (NSUInteger i = 0,count = self.imageNameArray.count; i < count; i++) {
UIImage *image = [UIImage imageNamed:self.imageNameArray[i]];
image = [self imageCompressWithSimple:image scaledToSize:CGSizeMake(SCREENWIDTH, SCREENHEIGHT)];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH * i, 0, SCREENWIDTH, SCREENHEIGHT)];
imageView.image = image;
[self.guideViewScrollView addSubview:imageView];
self.pageControl.currentPage = 0;
self.pageControl.numberOfPages = count;
}
}
- (void)pushFirstPage {
[LXKUserDefaultsTools userDefaultsSaveBool:YES key:@"isShowGuideView"];
B1_LXKLoginVC *firstPage = [[B1_LXKLoginVC alloc] init];
LXKNavigationController *nav = [[LXKNavigationController alloc] initWithRootViewController:firstPage];
UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
window.rootViewController = nav;
}
// 缩放到指定大小
- (UIImage*)imageCompressWithSimple:(UIImage*)image scaledToSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0,0,size.width,size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == self.guideViewScrollView) {
// 取到scrollView的偏移量好改变分页控件的currentPage
CGFloat x = scrollView.contentOffset.x;
// 根据偏移量四舍五入
_pageControl.currentPage = lround(x / SCREENWIDTH);
if (x > 2 * SCREENWIDTH) {
[self pushFirstPage];
}
}
}
@end