国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IOS開發基礎知識--碎片11

2019-11-14 19:12:05
字體:
來源:轉載
供稿:網友

1:AFNetwork判斷網絡狀態

#import “AFNetworkActivityIndicatorManager.h"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    //網絡    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];    [[AFNetworkReachabilityManager sharedManager] startMonitoring];    //網絡狀態判斷    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {        switch (status) {            case AFNetworkReachabilityStatusNotReachable:{                [self showMBPHudTipStr:@"當前無網絡連接"];                break;            }            case AFNetworkReachabilityStatusReachableViaWiFi:{                [LogUtil logUtilstring:@"WiFi網絡"];                break;            }            case AFNetworkReachabilityStatusReachableViaWWAN:{                [self showMBPHudTipStr:@"無線網絡"];                break;            }            default:                break;        }    }];       return YES;}

2:UIButton倒計時

當在倒計時uibutton不能被響應事件;-(void)startTime{    __block int timeout=60; //倒計時時間    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);    dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);    dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒執行    dispatch_source_set_event_handler(_timer, ^{        if(timeout<=0){ //倒計時結束,關閉            dispatch_source_cancel(_timer);            dispatch_async(dispatch_get_main_queue(), ^{                //設置界面的按鈕顯示 根據自己需求設置                [self.againBtn setTitle:@"重發驗證碼" forState:UIControlStateNormal];                self.againBtn.userInteractionEnabled = YES;                self.labNoMessage.text=@"沒有收到驗證碼嗎?";                self.labNoMessage.textColor=[UIColor redColor];            });        }else{            int seconds = timeout % 60;            NSString *strTime = [NSString stringWithFormat:@"%.2d", seconds];            dispatch_async(dispatch_get_main_queue(), ^{                //設置界面的按鈕顯示 根據自己需求設置                [self.againBtn setTitle:[NSString stringWithFormat:@"重發激活郵件(%@)",strTime] forState:UIControlStateNormal];                self.againBtn.userInteractionEnabled = NO;                self.labNoMessage.text=@"激活郵件發送成功";                self.labNoMessage.textColor=[UIColor colorWithHexString:@"84BF20"];                            });            timeout--;                    }    });    dispatch_resume(_timer);    }

3:判斷iphone設備

#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

4:在IOS8以下報一個自動布局的BUG,而在IOS8卻能正常運行

會導致APP掛掉,BUG內容:Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Auto Layout still required after executing -layoutSubviews.
UITableView’s implementation of -layoutSubviews needs to call super.’- (void)layoutSubviews{ //自動布局的內容放在super layoutSubviews前面 [self _updateConstraints]; [super layoutSubviews];}

5:與JS交互,并把JS代碼兼容android跟IOS

JS代碼:$(function () {    var u = navigator.userAgent, app = navigator.appVersion;    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('linux') > -1; //android終端或者uc瀏覽器    var isiOS = !!u.match(//(i[^;]+;( U;)? CPU.+Mac OS X/); //ios終端    if (isAndroid) {        $('#btn_Success').attr('href', 'javascript:mailActive.backHome()');    }    else if (isiOS) {        $('#btn_Success').attr('href', 'protoclo://backHome');    }});而IOS則是shouldStartLoadWithRequest:-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{    NSString *newURL=[[request URL] absoluteString];    if([newURL hasprefix:@"protoclo://"])    {        NSArray *stringArray=[newURL componentsSeparatedByString:@"//"];        if (stringArray.count>1&&[[stringArray objectAtIndex:1] isEqualToString:@"backHome"]) {            [self webJavascriptBackHome];        }    }    return YES;}注:比較好IOS的JS交互第三方插件WebViewJavascriptBridge;在IOS開發調試內嵌webView時可以用Safari進行調試,它可以設置出開發模式菜單,開發->ios simulator 就可以實現查看網頁的運行詳情(Safari->偏好設置-高級-在菜單中顯示“開發”);

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 法库县| 鄂伦春自治旗| 玛纳斯县| 南江县| 三台县| 邢台市| 葵青区| 武汉市| 城固县| 旅游| 耿马| 多伦县| 祁门县| 保德县| 通辽市| 玛多县| 蒙山县| 通榆县| 镇沅| 福建省| 玉门市| 建阳市| 吉木萨尔县| 开封县| 常德市| 岳普湖县| 卢湾区| 衡阳市| 浦城县| 宁德市| 鹤壁市| 治县。| 永顺县| 利辛县| 青州市| 台安县| 青岛市| 同仁县| 旅游| 辽阳市| 长宁县|