• iOS开发技巧(2)


    原文来自:coltfoal's website


    一不小心又总结出了第二个列表,就此罗列一下。

    [MFMailComposeViewController canSendMail]

    发送邮件之前最好先判断是否已经设置好邮箱账号,如果已经设置了,则直接弹窗发送,否则可以生成自己的提示框。如果不使用canSendMail方法判断,而直接判断MFMailComposeViewController是否为空,则系统会自动弹窗提示没有设置邮箱账户。

    语言本地化

    1.Project-->Info-->Localizations添加Chinese;
    2.修改Target-->Info-->Localization native development region设置为China 。

    可以让应用的语言变为中文,即包括图片查看器等显示系统语言的地方都能显示为中文。但邮件发送界面无法通过这种方式改变。

    阴影导致的滑动卡顿问题

    使用UICollectionView显示文件图标等列表时为了美化效果一般会添加阴影,但是添加阴影后滑动明显卡顿,是因为绘制阴影导致的问题。以下是StackOverflow上的解决方案。

    http://stackoverflow.com/questions/3677564/drawing-shadow-with-quartz-is-slow-on-iphone-ipad-another-way

    总结起来就是三行代码:

    self.contentView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.contentView.bounds].CGPath;
    self.contentView.layer.shouldRasterize = YES;
    self.contentView.layer.rasterizationScale = [[UIScreen mainScreen] scale];

    在初始化的时候调用这几行代码,滑动速度就提上去了。

    自定义AlertView

    重写UIAlertController,将自己的视图加进去就可以了。

    makeObjectsPerformSelector

    使NSArray的每个对象执行某个方法。
    可以通过这个方法把某个UIView的SubView全部移出父视图。

    UICollectionView滚动停止问题

    在边界处向上滑动UICollectionView并长按停止,松开手指发现UICollectionView不会回滚到原来的位置。需要在endDragging的方法里调整UICollectionView的位置。

    强制转屏

    // arc强制转屏
    - (void)forceInterfaceOrientationTo:(UIInterfaceOrientation)interfaceOrientation
    {
        UIDevice *device = [UIDevice currentDevice];
        SEL sel = NSSelectorFromString([NSString stringWithFormat: @"setOri%@tion:", @"enta"]);
    
        if ([device respondsToSelector: sel])
        {
            NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:sel]];
            [invocation setSelector:sel];
            [invocation setTarget:[UIDevice currentDevice]];
            int val = interfaceOrientation;
            [invocation setArgument:&val atIndex:2];
            [invocation invoke];
        }
    }
    

      

    // mrc强制转屏
    - (void) setInterfaceOrientationForciblyTo: (UIInterfaceOrientation)interfaceOrientation
    {
        UIDevice *device = [UIDevice currentDevice];
        SEL sel = NSSelectorFromString([NSString stringWithFormat: @"setOri%@tion:", @"enta"]);
    
        if ([device respondsToSelector: sel])
            [[UIDevice currentDevice] performSelector: sel withObject: (id)interfaceOrientation];
    }    
    

      

    往系统相册导入视频

    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum(videoPath))
    {
        UISaveVideoAtPathToSavedPhotosAlbum(videoPath, nil, nil, nil);
    }
    
  • 相关阅读:
    Unity3D实践系列08, MonoBehaviour类的各种触发事件
    Unity3D实践系列07,组件的启用或禁用开关,物体的的可见或不可见开关,以及相应事件
    Unity3D实践系列06,球体撞击物体游戏
    Linux tee的花式用法和pee
    bash内置命令mapfile:读取文件内容到数组
    Perl正则表达式引用
    Perl文件句柄引用
    透明代理、正向代理、反向代理的区别说明
    Perl回调函数和闭包
    一文搞懂:词法作用域、动态作用域、回调函数、闭包
  • 原文地址:https://www.cnblogs.com/coltfoal/p/4670253.html
Copyright © 2020-2023  润新知