iOS 啟動(dòng)廣告頁思路输瓜,直接 push瓦胎,首頁不出現(xiàn),上海華新鎮(zhèn)風(fēng)味
PM 提了個(gè)需求尤揣,啟動(dòng)廣告界面點(diǎn)擊了搔啊, 就直接進(jìn),不需要閃一下主界面北戏。
實(shí)現(xiàn)的思路负芋,多 window 模式
一般的廣告界面就是 Key Window 上面的遮罩(子視圖)。
要從廣告界面 push嗜愈,自然廣告界面就是一個(gè)控制器了旧蛾。
提升廣告界面的層級莽龟,才可以。
我提升到了 window 級別蚜点。
如果使用的是控制器轧房, 單 window (就是系統(tǒng)的), 然后切換就是 [UIApplication sharedApplication].keyWindow.rootViewController = ...
兩點(diǎn)考慮:
1, 切換即重新創(chuàng)建绍绘, 從廣告到首頁奶镶。
我希望首頁早加載,就必須給首頁一個(gè) window 容器陪拘。
2厂镇,首頁轉(zhuǎn)登錄,登錄再轉(zhuǎn)首頁
之前項(xiàng)目用的是切 keyWindow 的 rootViewController左刽, 然后首頁就丟了捺信,拿不到。登錄邏輯中欠痴,新建一個(gè)迄靠,我覺得比較可惜。
使用多 window , 拿回首頁喇辽,可以在內(nèi)存上復(fù)用掌挚。
@interface AppDelegate
// 主流程
@property (strong, nonatomic) UIWindow *window;
// 廣告
@property (strong, nonatomic) UIWindow *adWindow;
// 登錄
@property (strong, nonatomic) UIWindow *loginWindow;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] init];
self.window.frame = [UIScreen mainScreen].bounds;
UITabBarController * tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = UIColor.redColor;
self.window.rootViewController = tabBarController;
self.adWindow = [[UIWindow alloc] init];
self.adWindow.frame = [UIScreen mainScreen].bounds;
self.adWindow.rootViewController = [[UINavigationController alloc] initWithRootViewController: [[AdvertiseViewController alloc] init]];;
[self.adWindow makeKeyAndVisible];
return YES;
}
采用了三個(gè) window, 一個(gè)主流程,一個(gè)廣告菩咨, 一個(gè)登錄吠式,
KeyAndVisible 的是廣告 window.
( 項(xiàng)目原因,廣告都是實(shí)時(shí)請求抽米。不是市面上的異步緩存特占,下次使用。 華新鎮(zhèn)風(fēng)味)
問題就是如果廣告倒計(jì)時(shí)三秒云茸,用戶沒有點(diǎn)擊是目,
注意事項(xiàng):
需要在 Target 的 General 選項(xiàng)卡中, 指定 Main Interface 為空标捺。
建議刪除 main.storyboard.
因?yàn)閱?dòng)的時(shí)候切換 window, 就不能走 main.storyboard 了.
未實(shí)現(xiàn)的思路
缺點(diǎn):
沒有轉(zhuǎn)場動(dòng)畫 transition
內(nèi)存管理胖笛, 因?yàn)橛脩艨吹降?window 只有一個(gè)。
廣告業(yè)務(wù)處理完后宜岛,切換回首頁 window, 就應(yīng)該釋放廣告 window.
( 廣告 window 是 appDelegate 的屬性长踊,appDelegate 是單例, 所以 appDelegate 的廣告 window 屬性萍倡,初始化后身弊,會(huì)一直都存在)
在這個(gè)時(shí)機(jī)寫, appDelegate.adWindow = nil
, 就會(huì)黑光一閃。
這肯定是不行的阱佛。
需要在之后找地方釋放帖汞,代碼會(huì)亂一些。
iOS 啟動(dòng)廣告界面凑术,一般是在 window 上添加子視圖翩蘸。
UIWindow *window = [UIApplication sharedApplication].delegate.window;
[window addSubview: self];
廣告界面就是首頁 rootViewController ( 或者其子 Controller )上面的遮罩。點(diǎn)擊廣告頁淮逊,一般是通知首頁的 topViewController push 出廣告的內(nèi)容控制器催首。
一般的 App 啟動(dòng)加載廣告頁面思路都是這么寫的。 這篇不錯(cuò)泄鹏。
這種思路挺好的郎任,一般的廣告界面的 link 是 deep link, 與 app 強(qiáng)交互,先把整個(gè) app 的框架(首頁)加載出來备籽,再進(jìn)入業(yè)務(wù)層舶治。
我看了一下喜馬拉雅的效果,也覺得挺好的车猬。
華新鎮(zhèn)的產(chǎn)品經(jīng)理很硬霉猛。
相關(guān)代碼: https://github.com/BoxDengJZ/solution_launch_UI
其他技術(shù)點(diǎn):
可以網(wǎng)絡(luò)請求異步發(fā)起,下次使用珠闰,AFNetworking 的事情韩脏。
圖片緩存策略,SDWebImage 的事情铸磅。
??
??
封裝 ,除了 數(shù)據(jù)是 只讀 的杭朱。
數(shù)據(jù) 通過 操作 修改阅仔。
還有 一種類的 層級關(guān)系。
對象 的 屬性弧械,不能 跨越 層級八酒,直接訪問到。
必須是刃唐, 一級一級 訪問羞迷。修改
//self.orderDetailInfo.packageList[i].productList[j] = [OrderDetailProduct yy_modelWithDictionary: orderDetailProduct];
[HttpRequestManager getOrderDetailParams:requestDic success:^(id response, id data, NSString *Message) {
[MBProgressHUD hideHUD];
NSDictionary *responseDic = (NSDictionary *)data;
OrderDetail * orderDetailInfo = [OrderDetail yy_modelWithDictionary: responseDic];
self.orderDetailInfo = orderDetailInfo;
// NSInteger i = 0;
NSMutableArray * tempOrders = [[NSMutableArray alloc] initWithCapacity: orderDetailInfo.packageList.count];
for (OrderPackageList * orderPackageList in orderDetailInfo.packageList) {
OrderPackageList * tempPackageList = orderPackageList;
// NSInteger j = 0;
NSMutableArray * tempProducts = [[NSMutableArray alloc] initWithCapacity: orderPackageList.productList.count];
for (NSDictionary * orderDetailProduct in orderPackageList.productList) {
//self.orderDetailInfo.packageList[i].productList[j] = [OrderDetailProduct yy_modelWithDictionary: orderDetailProduct];
OrderDetailProduct * tempDetailProduct = [OrderDetailProduct yy_modelWithDictionary: orderDetailProduct];
[tempProducts addObject: tempDetailProduct];
// j++;
}
tempPackageList.productList = tempProducts;
[tempOrders addObject: tempPackageList];
// i++;
}
self.orderDetailInfo.packageList = tempOrders;
[self.orderDetailTableView reloadData];
??
??
??
Mock ,
在 客戶端 測試 Server 邏輯,
在 移動(dòng)端 直接 修改 數(shù)據(jù)画饥,
同樣有 Mock 的 效果衔瓮。