IOS開發基礎知識--片段51,ios基礎知識--51

來源:互聯網
上載者:User

IOS開發基礎知識--片段51,ios基礎知識--51

1:https關閉認證跟網域名稱的驗證

    AFSecurityPolicy *securityPolicy = [AFSecurityPolicy defaultPolicy];    securityPolicy.allowInvalidCertificates = YES;    securityPolicy.validatesDomainName = NO;    _manager.securityPolicy = securityPolicy;

如果報 In order to validate a domain name for self signed certificates, you MUST use pinning 也是上面這種方式進行解決

2: iOS UIWebView 訪問https繞過認證驗證的方法

@implementation NSURLRequest (NSURLRequestWithIgnoreSSL)+ (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host{    return YES;}@end

3:SDWebImage載入圖片繞過認證

    [myImageView sd_setImageWithURL:[NSURL URLWithString:replyModel.reply_name] placeholderImage:[UIImage imageNamed:@"default_header"]  options:SDWebImageAllowInvalidSSLCertificates]

4:關於Https一些不錯的文章介紹

http://oncenote.com/2014/10/21/Security-1-HTTPS/http://www.jianshu.com/p/2d72ef8dbf5ahttp://www.jianshu.com/p/b03ae4a1a2d3https://github.com/cos6meteors/YMHttpsTest

5:強制去除HTML標籤的文本

+ (NSString *)getStandarString:(NSString *)str{        NSArray *components = [str componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];    NSMutableArray *componentsToKeep = [NSMutableArray array];        for (int i = 0; i < [components count]; i = i + 2) {                NSString *str = [components objectAtIndex:i];        if (str.length) {            [componentsToKeep addObject:[components objectAtIndex:i]];        }                    }        NSString *plainText = [componentsToKeep componentsJoinedByString:@"\n"];        plainText = [[[plainText description]stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@""]stringByReplacingOccurrencesOfString:@" " withString:@""];        return plainText;    }

 6: iOS8以後第三方鍵盤,擷取高度為0的問題

IOS8.0之後可以安裝第三方鍵盤,如搜狗IME之類的。
獲得的高度都為0.這是因為鍵盤彈出的方法:- (void)keyBoardWillShow:(NSNotification *)notification需要執行三次,你如果列印一下,你會發現鍵盤高度為:第一次:0;第二次:216:第三次:282.並不是擷取不到高度,而是第三次才擷取真正的高度.
可以在UIKeyboardDidChangeFrameNotification的通知中實現,這裡需要注意的是:在彈出鍵盤時該方法執行3次,需要進行處理,已達到所要的效果.
註冊鍵盤事件:
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyBoardChange:) name:UIKeyboardDidChangeFrameNotification object:nil];

pragma mark–鍵盤改變事件的觸發

(void)keyBoardChange:(NSNotification *)notification{NSDictionary *dict = notification.userInfo; NSValue *aValue = [dict objectForKey:UIKeyboardFrameEndUserInfoKey]; NSNumber *animationTime = [dict objectForKey:@”UIKeyboardAnimationDurationUserInfoKey”];CGRect keyboardRect = [aValue CGRectValue]; CGFloat keyHeight = (HEIGHT(self.view)-Y(searBar)-HEIGHT(searBar))-keyboardRect.size.height; if(keyHeight<=0){ [UIView animateWithDuration:[animationTime doubleValue] animations:^{ self.view.frame =CGRectMake(0, keyHeight, WIDTH(self.view), HEIGHT(self.view)); } completion:^(BOOL finished) { }]; }}

pragma mark–鍵盤隱藏事件

(void)keyBoardDidHide:(NSNotification *)notification{ self.view.frame = CGRectMake(0, 0, WIDTH(self.view), HEIGHT(self.view)); }

 

另有一份代碼:

- (void)keyboardWillShow:(NSNotification *)notification { CGFloat curkeyBoardHeight = [[[notification userInfo] objectForKey:@"UIKeyboardBoundsUserInfoKey"] CGRectValue].size.height;    CGRect begin = [[[notification userInfo] objectForKey:@"UIKeyboardFrameBeginUserInfoKey"] CGRectValue];    CGRect end = [[[notification userInfo] objectForKey:@"UIKeyboardFrameEndUserInfoKey"] CGRectValue];        // 第三方鍵盤迴調三次問題,監聽僅執行最後一次    if(begin.size.height>0 && (begin.origin.y-end.origin.y>0)){        keyBoardHeight = curkeyBoardHeight;        [self showKeyboard:notification];    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.