iOS零碎小知识

  1. 使应用不会自动锁屏。
    [UIApplication sharedApplication].idleTimerDisabled=YES;//不自动锁屏
    [UIApplication sharedApplication].idleTimerDisabled=NO;//自动锁屏

  2. 程序图标不加高光效果
    iOS程序build到手机上时,默认的桌面图标是有高亮的光圈效果的。如果您要去掉这一高亮特效,可以在程序的 info.plist 设置Icon already includes gloss effects,值设定为YES,默认值是NO。程序上传到App Store 也就不会在图标上添加高亮特效了。

  3. 判断屏幕分辨率
    BOOL retina = CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size);
    返回true说明当前分辨率是CGSizeMake(640, 960),false则不是

  4. 遇到类似这样的错误failed to get the task for process XXX
    多半是证书问题,project和targets证书都要是可用并且正确的证书才行。

  5. 出现这样的问题Property's synthesized getter follows Cocoa naming convention for returning 
    Property's synthesized getter follows Cocoa naming convention for returning.
    今天早上在整理代码的时候发现了如上警告。
    在网上查询后发现,是因为苹果在新的编码,不推荐变量以new、copy等关键字开头。
    突然想起来之前也有朋友问过类似的问题。特做以记录。
    也希望大家在以后编码的时候,能够多多注意。

  6. 快速获取沙盒路径
    #define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@
    "Documents"]

  7. 判断邮箱是否合法
    - (BOOL) validateEmail: (NSString *) candidate {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}"; 
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; 
    return [emailTest evaluateWithObject:candidate];
    }
  8. 显示网络活动状态 
    UIApplication* app = [UIApplication sharedApplication];
    app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO


  9. 显示一组连续的图片(类似动画效果)
    NSArray *myImages = [NSArray arrayWithObjects:
        [UIImage imageNamed:@"myImage1.png"],
        [UIImage imageNamed:@"myImage2.png"],
        [UIImage imageNamed:@"myImage3.png"],
        [UIImage imageNamed:@"myImage4.gif"],
        nil];
    
    UIImageView *myAnimatedView = [UIImageView alloc];
    [myAnimatedView initWithFrame:[self bounds]];
    myAnimatedView.animationImages = myImages;
    myAnimatedView.animationDuration = 0.25; // seconds
    myAnimatedView.animationRepeatCount = 0; // 0 = loops forever
    [myAnimatedView startAnimating];
    [self addSubview:myAnimatedView];
    [myAnimatedView release];


  10. 页面切换效果设置
    controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:controller animated:YES];


    可供使用的效果:
    UIModalTransitionStyleCoverVertical
    UIModalTransitionStyleFlipHorizontal
    UIModalTransitionStyleCrossDissolve
    UIModalTransitionStylePartialCurl


    恢复之前的页面:
    [self dismissModalViewControllerAnimated:YES];

  11. 为UIImageView添加单击事件:
    imageView.userInteractionEnabled = YES;
    
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)];
    
    [imageView addGestureRecognizer:singleTap];

  12. 获取应用版本

    NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
    NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
    NSString*appName =[infoDict objectForKey:@"CFBundleDisplayName"];


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值