開發(fā)要求:
聯(lián)網(wǎng)的時候,有協(xié)議數(shù)據(jù)的時候從上往下彈出界面,每個用戶必須同意協(xié)議才能使用app,否則退出應(yīng)用(exit(0));
我的解決方案:在comment類里,寫個類方法,實(shí)現(xiàn)
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"showUserAgreementViewController"]) {
CATransition *transition = [CATransition animation];
transition.duration = 0.3f;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromBottom;
[ESControllerManager pushViewController:@"ESUserAgreementViewController" Parameters:@{@"title":daRenAgreementTitle,@"content":daRenAgreementContent,@"ID":@(daRenAgreementID)} Animated:NO];
[[ESControllerManager getRootNavigationController].view.layer addAnimation:transition forKey:nil];
}
});
bug:
1,當(dāng)手機(jī)沒電,強(qiáng)制關(guān)機(jī)等突然中止應(yīng)用的時候,再此打開應(yīng)用時,協(xié)議不能彈出;
為防止界面彈出多次,我在本地保存一個bool值,標(biāo)示界面是否在彈出boolForKey:@"showUserAgreementViewController",問題就在這里,如果突然中止應(yīng)用,這個bool值還是yes,界面如何能彈出來呢
2,當(dāng)?shù)顷憫?yīng)用的時候,彈出主頁,協(xié)議不彈出;
這種情況,主界面第二次彈出還帶有動畫,其實(shí)還是蠻好玩的,這個問題是在push上,當(dāng)兩個界面同時彈出時,一個界面覆蓋另一個界面,顯示出來的界面就有一定的不確定行
解決方案:
應(yīng)用代碼:
if (![ESUserAgreementViewController IsShow]) {
[ESUserAgreementViewController Show:daRenAgreementTitle Content:daRenAgreementContent ID:daRenAgreementID];
}
界面搭建:將界面放到一個window上,界面是否彈出標(biāo)示 設(shè)置成靜態(tài)變量
static UIWindow* window;
static BOOL isShow;
@implementation ESUserAgreementViewController
+(BOOL)IsShow
{
return isShow;
}
+(void)Init
{
if(!window)
{
window=[[UIWindow alloc]initWithFrame:CGRectMake(0, 0, ESWidth, ESHeight)];
window.windowLevel=1499.9;
window.hidden=YES;
[window makeKeyAndVisible];
}
}
+(void)Show:(NSString*)title Content:(NSString*)content ID:(int)ID
{
isShow=YES;
[ESUserAgreementViewController Init];
ESUserAgreementViewController* viewController=[[ESUserAgreementViewController alloc]init];
[viewController setParameters:@{@"title":title,@"content":content,@"ID":@(ID)}];
for (UIView* view in window.subviews) {
[view removeFromSuperview];
}
[window setRootViewController:viewController];
[window addSubview:viewController.view];
window.frame=CGRectMake(0, -ESHeight, ESWidth, ESHeight);
window.hidden=NO;
[UIView animateWithDuration:0.3 animations:^{
window.frame=CGRectMake(0, 0, ESWidth, ESHeight);
}];
}
+(void)Hide
{
isShow=NO;
[UIView animateWithDuration:0.3 animations:^{
window.frame=CGRectMake(0, -ESHeight, ESWidth, ESHeight);
}];
}