iOS_tips

作者: 798798123 | 来源:发表于2017-04-06 22:06 被阅读22次

    21、iOS截图长图代码实现

    + (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView;
    + (UIImage *)cz_longFigureForScrollView:(UIScrollView *)scrollView {
        UIImage* image = nil;
        UIGraphicsBeginImageContextWithOptions(scrollView.contentSize, YES, 0.0);
        
        //保存collectionView当前的偏移量
        CGPoint savedContentOffset = scrollView.contentOffset;
        CGRect saveFrame = scrollView.frame;
        
        //将collectionView的偏移量设置为(0,0)
        scrollView.contentOffset = CGPointZero;
        scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
        
        //在当前上下文中渲染出collectionView
        [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
        //截取当前上下文生成Image
        image = UIGraphicsGetImageFromCurrentImageContext();
        
        //恢复collectionView的偏移量
        scrollView.contentOffset = savedContentOffset;
        scrollView.frame = saveFrame;
        
        UIGraphicsEndImageContext();
        
        if (image != nil) {
            return image;
        }else {
            return nil;
        }
    }
    

    20、审核中可能被怀疑的问题

    1.1.6 - Include false information, features, or misleading metadata.
    2.3.0 - Undergo significant concept changes after approval
    2.3.1 - Have hidden or undocumented features, including hidden "switches" that redirect to a gambling or lottery website
    3.1.1 - Use payment mechanisms other than in-app purchase to unlock features or functionality in the app
    3.2.1 - Do not come from the financial institution performing the loan services
    4.3.0 - Are a duplicate of another app or are conspicuously similar to another app
    5.2.1 - Were not submitted by the legal entity that owns and is responsible for offering any services provided by the app
    5.2.3 - Facilitate illegal file sharing or include the ability to save, convert, or download media from third party sources without explicit authorization from those sources
    5.3.4 - Do not have the necessary licensing and permissions for all the locations where the app is used
    

    19、注册错误,不允许注册时要求用户填写身份证+姓名等敏感信息。


    registererror.png

    18、IPV6审核失败解决方案


    ipv6error.png
    // app在国内环境登录使用一切正常,审核人员登录时会提示连接失败,报500错误!并且期初错误无法复现。
    // 错误复现场景,在手机设置->通用->地区与时间->将国家改为美国,成功复现连接失败错误!
    // 配合后台同事调试,发现为语言包配置错误导致连接失败,没有返回任何内容。
    // 参考链接:https://www.jianshu.com/p/5e06e8dd2fc4
    

    17、IPV6审核失败解决方案

    // https://blog.csdn.net/pyf_1993/article/details/73177685
    // https://blog.csdn.net/wangyanchang21/article/details/73920923
    // https://jiandanxinli.github.io/2016-08-06.html
    

    16、SDWebImage在4.0之后不再支持加载gif动图,需要单独导入支持gif的库即可。

    pod 'SDWebImage/GIF'
    // 使用FLAnimatedImageView来代替UIImageView即可加载Gif图片
    

    15、测试安装app时报错“This application does not support this device’s CPU type.”

    // 原因:32位的Application已经被苹果淘汰,不再支持安装!
    // 解决:项目中找到 Build Settings -> Architectures ,修改为 standard architectures 即可!
    

    14、如何在用户退出时清空单例对象值,并且保证在重新登录时可以新建单例对象?

    + (void)qmx_userDealloc {
        onceToken = 0;
        _instance = nil;
    }
    
    // 1. 必须把static dispatch_once_t onceToken; 这个拿到函数体外,成为全局的. 
    // 2.只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
    // http://blog.csdn.net/u012847940/article/details/51422783
    

    13、UICollectionView用法补充

    // MARK: - 1.header注册方式
    // 参数2 在头文件最顶部 header 或 footer
    [cv registerClass:[ZXFPhotoAlbumHeaderView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID];
    // MARK: - 2.显示header
    // 需要在布局属性中设置header的size
    self.headerReferenceSize = CGSizeMake(self.collectionView.width, 40);
    // MARK: - 3.其他
    // header类型是继承自 UICollectionReusableView
    // 返回视图的方法
    - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
        
        ZXFPhotoAlbumHeaderView *headerV = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerID forIndexPath:indexPath];
        
        headerV.title = [NSString stringWithFormat:@"这是第 %@ 组", @(indexPath.section).description];
        
        return headerV;
    }
    

    12.iOS Crash文件分析

    http://ios.jobbole.com/82120/
    http://www.jianshu.com/p/62a47926334d
    http://ios.jobbole.com/93238/
    

    11.UITextField文本框的光标处理

    // 会影响所有光标颜色
    [[UITextField appearance] setTintColor:[UIColor blackColor]];
    // 单独修改某一个光标颜色
    textField.tintColor = [UIColor redColor]; 
    // 不显示光标
    textField.tintColor = [UIColor clearColor]; 
    

    10.控件超出父控件范围无法响应的问题

    - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
        
        //1. 边界情况:不能响应点击事件
        BOOL canNotResponseEvent = self.hidden || (self.alpha <= 0.01f) || (self.userInteractionEnabled == NO);
        if (canNotResponseEvent) {
            return nil;
        }
        
        //2. 最后处理 TabBarItems 凸出的部分、添加到 TabBar 上的自定义视图、点击到 TabBar 上的空白区域
        UIView *result = [super hitTest:point withEvent:event];
        if (result) {
            return result;
        }
        
        for (UIView *subview in self.subviews.reverseObjectEnumerator) {
            CGPoint subPoint = [subview convertPoint:point fromView:self];
            result = [subview hitTest:subPoint withEvent:event];
            if (result) {
                return result;
            }
        }
        return nil;
    }
    

    9.WebView问题

    问题:使用UIWebView加载链接时,底部总是出现黑色的横条。
    解决:设置webView的opaque属性为NO,背景颜色设置clearColor即可。
    

    8.友盟分享集成问题

    集成选择了微信、QQ、新浪微博。
    问题:在弹出的分享面板中微信始终不能出现。
    解决:将完整的微信SDK,切换为精简版的微信分享SDK,界面正常展示
    

    7.字体加粗及倾斜

    字体加粗
    loginLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
    字体加粗并且倾斜
    loginLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];
    // 参考网址
    // http://blog.csdn.net/x1135768777/article/details/7526259
    

    6.调整文字间距和行距
    原文链接:http://www.jianshu.com/p/b7a2314e780a

    #import <UIKit/UIKit.h>
    
    @interface UILabel (ChangeLineSpaceAndWordSpace)
    
    /**
     *  改变行间距
     */
    + (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space;
    
    /**
     *  改变字间距
     */
    + (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space;
    
    /**
     *  改变行间距和字间距
     */
    + (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace;
    
    @end
    
    #import "UILabel+ChangeLineSpaceAndWordSpace.h"
    
    @implementation UILabel (ChangeLineSpaceAndWordSpace)
    
    + (void)changeLineSpaceForLabel:(UILabel *)label WithSpace:(float)space {
    
        NSString *labelText = label.text;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:space];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
        label.attributedText = attributedString;
        [label sizeToFit];
    
    }
    
    + (void)changeWordSpaceForLabel:(UILabel *)label WithSpace:(float)space {
    
        NSString *labelText = label.text;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(space)}];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
        label.attributedText = attributedString;
        [label sizeToFit];
    
    }
    
    + (void)changeSpaceForLabel:(UILabel *)label withLineSpace:(float)lineSpace WordSpace:(float)wordSpace {
    
        NSString *labelText = label.text;
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText attributes:@{NSKernAttributeName:@(wordSpace)}];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:lineSpace];
        [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
        label.attributedText = attributedString;
        [label sizeToFit];
    
    }
    
    @end
    

    1.cornerstone上传默认忽略.a库文件,导致项目编译报错!

      解决:设置cornerstone的偏好设置,不要忽略.a库文件即可!
    cornerstone ->preferences->Subversion->关闭 Use default global ignores -> 删除 *a选项!
    
    cornerstone.png

    2.环信推送测试收不到推送消息

      -> 1.测试证书的软件 Ease APNs Provider 可以测试生成的cer推送证书是否有问题
      -> 2.按照文档进行排查 http://www.imgeek.org/article/825307548
      
    错误:上传的测试证书,环境选择成了开发环境!
    解决:重新上传证书,正确选择环境即可
    

    3.UISlider控件触发值改变事件比较频繁!

    UISlider *slider = [[UISlider alloc] init];
    UIImage *img = [UIImage imageNamed:@"fontchange"];
    // 只在手指抬起时触发一次值改变事件
    slider.continuous = NO;
    [slider setThumbImage:img forState:UIControlStateNormal];
    

    4.”A valid provisioning profile for this executable was not found“

    从描述上可以看到说:对于可执行provisioning profile 没有被找到。所以网上有很多答案是说你provisioning profile没有被找到,需要重新导入之类的。
     http://blog.sina.com.cn/s/blog_71715bf8010164z5.html
    但是我碰到的原因是我在Project中将Code Signing Identity中将其设置成了iPhone Develop,但是在Target中的Code Signing Identity并没有自动切换过来,我发现在Target中的Code Signing Identity还是我之前的设的iPhone Distribution,
    所以看到这里就知道了,iPhone Distribution 的provisioning profile肯定是不能运行的,所以把Target中的Code Signing Identity也设置成iPhone Develop就ok了,这样一切都说的通了,唯一不合理的就是在Project切换Code Signing Identity并编译,但xCode没有自动将编译后的Target设置成和Project中的一致
    

    5.上传错误
    提交审核之前,如果需要更新构建版本,只需要更新CFBundleVersion就可以,不需要更改版本号!


    屏幕快照 2017-04-28 上午9.35.38.png
    解决了第一个错误就没问题了,原因是环信SDK中支持了X86_64
    http://docs.easemob.com/im/300iosclientintegration/20iossdkimport
    
    屏幕快照 2017-04-28 上午10.07.36.png

    相关文章

      网友评论

          本文标题:iOS_tips

          本文链接:https://www.haomeiwen.com/subject/vmccattx.html