IOS开发基础知识--碎片51

发布时间:2016-12-19 11:49:27编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"IOS开发基础知识--碎片51 ",主要涉及到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/2d72ef8dbf5a
http://www.jianshu.com/p/b03ae4a1a2d3
https://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之后可以安装第三方键盘,如搜狗输入法之类的。
获得的高度都为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];
    }


上一篇:calltree看代码调用图
下一篇:Spring框架--AOP编程

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款