B8-iOS 开发的一些tips

1、真机调试

    1> 项目更换了证书和描述文件重新调试时,会运行失败,提示The application could not be verified.此时把设备上原项目删除,再调试运行即可。

    2> Code Signing证书为distribution时,调试项目会提示加载失败,启动超时(time out),改为developer证书即可。

 

2、隐藏手机状态栏的几个方法

    方法一、

// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.

@property(nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden;

- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_AVAILABLE_IOS(3_2);

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; //不知道怎么使。。。

     方法二、

- (BOOL)prefersStatusBarHidden

{

    return YES;

}

      方法三、创建window级别设置为UIWindowLevelAlert,将状态栏遮住(常见发微博等提示消息功能)

static UIWindow *_window;

@implementation HelpViewController



- (void)viewDidLoad

{

    [super viewDidLoad];

    _window = [[UIWindow alloc] init];

    _window.frame = self.view.frame;

    _window.windowLevel = UIWindowLevelAlert;

    [_window addSubview:textView];

    _window.hidden = NO;

}

 

3、Application loader的使用

    详细内容链接,http://blog.csdn.net/nogodoss/article/details/8217062

 

4、宏替换NSLog函数,在发布后使NSLog函数无效,避免NSLog耗费性能

    #ifdef DEBUG // 处于开发阶段

    #define MYLog(...) NSLog(__VA_ARGS__)

    #else // 处于发布阶段

    #define MYLog(...)

    #endif

 

5、要转成URL的字符串如果包含汉字,需要先将字符串转义

NSString *str = [NSString stringWithFormat:@"http://%@:%d/%@/cpi/msg/findDocumentId?loginname=%@",constants.webServer, constants.webPort, constants.man,self.userid];

NSString *urlString = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *url = [NSURL URLWithString:urlString];

 

6、应用评分功能的实现

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms://itunes.apple.com/cn/app/id%d?mt=8",ZAppleID]]];

// 打开手机上的iTunes Store显示应用,ZAppleID是应用在iTunesConnect的Apple ID

        

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"itms-apps://itunes.apple.com/cn/app/id%d?mt=8",ZAppleID]]];

// 打开手机上的App Store显示应用,ZAppleID是应用在iTunesConnect的Apple ID

 

7、应用内实现应用评分(不跳转)(评论按钮无效,可下载)

    此方法从iOS6开始,参考文章:http://blog.sina.com.cn/s/blog_6b8c3d7a0101apjz.html

  1. 导入StoreKit.framework
  2. #import <StoreKit/SKStoreProductViewController.h>
  3. 遵守代理 <SKStoreProductViewControllerDelegate>
  4. 实现如下:
- (void)evaluate

{    

    //初始化控制器

    SKStoreProductViewController *storeProductViewContorller = [[SKStoreProductViewController alloc] init];

    //设置代理请求为当前控制器本身

    storeProductViewContorller.delegate = self;

    //加载一个新的视图展示

    [storeProductViewContorller loadProductWithParameters:

     //appId唯一的

     @{SKStoreProductParameterITunesItemIdentifier : @"967710424"} completionBlock:^(BOOL result, NSError *error) {

         //block回调

         if(error){

             NSLog(@"error %@ with userInfo %@",error,[error userInfo]);

         }else{

             //模态弹出appstore

             [self presentViewController:storeProductViewContorller animated:YES completion:^{

                 

             }

              ];

         }

     }];

}



//取消按钮监听

- (void)productViewControllerDidFinish:(SKStoreProductViewController *)viewController

{

    [self dismissViewControllerAnimated:YES completion:^{

        ZLog(@"杀了控制器");

    }];

}

 

8、Xcode断点

      只要把断点设在 property 的声明上,就可以断到这个 property 所有的改变。Objective-C 和 Swift 通用。(补充,应该是断在了此属性的setter和getter方法。)

 

9、NSJSONReadingOptions

NSJSONReadingMutableContainers // 返回可变容器,NSMutableDictionary或NSMutableArray。



NSJSONReadingMutableLeaves // 返回的JSON对象中字符串的值为NSMutableString



NSJSONReadingAllowFragments // 允许JSON字符串最外层既不是NSArray也不是NSDictionary,但必须是有效的JSON Fragment。例如使用这个选项可以解析 @“123” 这样的字符串。

 

 10、scrollView的几个属性contentSize contentOffset contentInset

    1>不能向上滑动很可能是因为contentSize的大小不对。

     scrollView的几个属性contentSize contentOffset contentInset。

contentSize是scrollview可以滚动的区域,比如frame = (0 ,0 ,320 ,480) contentSize = (320 ,960),代表你的scrollview可以上下滚动,滚动区域为frame大小的两倍。

contentOffset是scrollview当前显示区域顶点相对于frame顶点的偏移量,比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480。

contentInset是scrollview的contentview的顶点相对于scrollview的位置,例如你的contentInset = (0 ,100),那么你的contentview就是从scrollview的(0 ,100)开始显示。

     另外UITableView是UIScrollView的子类,它们在上述属性又有所不同,tabelview的contentsize是由它的下列方法共同实现的:

- (NSInteger)numberOfSections;

- (NSInteger)numberOfRowsInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;

    它会自动计算所有的高度和来做为它的contentsize的height。

 

11、关于点击状态栏不回到顶部问题解决方法

     @property(nonatomic) BOOL  scrollsToTop;        // default is YES.
     设置这个属性,可以让点击状态栏不回到顶部,但是如果我们需要让他回到顶部,程序又不响应操作,这时的解决方法:
     刚才上面的官方文档说了,只有当一个主控制器有一个scrollview 并把这个属性设置为yes,其他的scrollview.scrollsToTop = NO 这样才会响应这个事件,原理很简单,如果有2个scrollview,系统根本不知道你需要哪个滚动到最上面。

 

12、UIImageView显示成圆形的两种方案

     1》剪切imageView

    self.faviconImageV.layer.cornerRadius = self.faviconImageV.width * 0.5; // 一定要有frame

    self.faviconImageV.layer.masksToBounds = YES; // 默认NO

//    self.faviconImageV.layer.borderWidth = 5.0;

//    self.faviconImageV.layer.borderColor = [UIColor purpleColor].CGColor; 

     2》画出一个圆的image

self.faviconImageV.image = [self circleImage:[UIImage imageWithData:data] withParam:0];



// 此方法可以写在UIImage的分类里面

- (UIImage *) circleImage:(UIImage *) image withParam:(CGFloat) inset

{

    UIGraphicsBeginImageContext(image.size);

    CGContextRef context =UIGraphicsGetCurrentContext();

    

    //圆的边框宽度为2,颜色为红色

    CGContextSetLineWidth(context,2);

    CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);

    CGRect rect = CGRectMake(inset, inset, image.size.width - inset *2.0f, image.size.height - inset *2.0f);

    CGContextAddEllipseInRect(context, rect);

    CGContextClip(context);

    

    //在圆区域内画出image原图

    [image drawInRect:rect];

    CGContextAddEllipseInRect(context, rect);

    CGContextStrokePath(context);

    

    //生成新的image

    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    

    return newImage;

 

13、UIColor,CGColor,CIColor三者的区别和联系

参考链接:http://www.cnblogs.com/smileEvday/archive/2012/06/05/UIColor_CIColor_CGColor.html#commentform%C3%AF%C2%BC%C2%88%C3%A5%C2%8D%C2%9A

 

14、为项目替换发布证书和描述文件后,打包一直报错的问题

 In Xcode Preferences

  • > In Accounts click on your Apple ID
  • > Click View Details
  • > Click on your projects Provisioning Profile
  • > Click refresh button bottom left

 

15、tabBar的代理默认就是tabBarViewController

     若用代码再去设置tabBar的代理是tabBarViewController,运行就会报错。

     错误信息:Changing the delegate of a tab bar managed by a tab bar controller is not allowed.

 

16、.gitignore文件的使用

      例如:忽略所有的.DS_Store文件。

B8-iOS 开发的一些tips

参考链接:http://www.cnblogs.com/haiq/archive/2012/12/26/2833746.html

 

17、在github更新自己fork的代码

参考链接:http://www.360doc.com/content/13/1217/22/14570841_338006038.shtml

 

18、打开car文件的方法

    1、http://joaoa.com/ThemeEngine/

    2、https://github.com/devcxm/iOS-Images-Extractor

 

19、LaunchImage的一个错误解决方案。

        项目适配iOS7或之前时,Xcode会警告,要求在Images.xcassets使用LaunchImage。删除Launch Screen.xib,在Images.xcassets添加LaunchImage之后。下方第二张图,选中的地方会出现LaunchImage选项,此时如果删除Images.xcassets包含的LaunchImage,重新使用Launch Screen.xib时,运行就会报错,即下面第一张图。然后在第二张图里面删除LaunchImage选项即可解决。

你可能感兴趣的:(tips)