0
点赞
收藏
分享

微信扫一扫

iOS小技能:通讯录


引言

iOS处理语言工具CFStringTransform : 智能地处理用户的输入内容,经典应用场景【索引】

  • 通讯录demo源码

1、原理:通过对用户输入内容,利用CFStringTransform变换,可以轻松实现实现一个通用的搜索index

2、 特色:搜索内容可以是多语言的 

I 、通讯录

1.1 知识储备

有2个框架可以访问用户的通讯录:

AddressBookUI.framework:提供了联系人列表界面、联系人详情界面、添加联系人界面等;一般用于选择联系人 AddressBook.framework:纯C语言的API,仅仅是获得联系人数据;没有提供UI界面展示,需要自己搭建联系人展示界面;里面的数据类型大部分基于Core Foundation框架,要经常进行类型转换。使用麻烦。

联系人属性包括以下类型

简单属性:姓、名等;多重属性:电话号码、电子邮件等;组合属性:地址等

申请通讯录访问授权的代码,通常放在AppDelegate中

1.2 案例

iOS处理语言工具CFStringTransform : 智能地处理用户的输入内容,经典应用场景【索引】

  • 从下载通讯录demo源码


II 、 iOS APP 内的本地化切换


III、界面框架

iOS小技能:通讯录_.net

1、push的时候隐藏buttomBar

iOS小技能:通讯录_控件_02

2、staticcells类型的tableView,已经确定了分组和分组的cell个数,在vc中实现的代理方法应该返回分组数字不应该小于xib的分组数。

3.1 框架设计

1、设计一个主头文件,来包含框架内部所有的头文件 2、如何接口文件只是用于声明的话,尽量使用@class,而不是#import

#import <UIKit/UIKit.h>
@class HSContactsModel;

3、装配数据时,要确保已经存在视图

@property (nonatomic,strong) HSContactsModel *model;//模型属性,的setter方法如果在跳转到VC之前调用,不会达到装配view的结果--因为VC的View只有在要显示的时候才加载,

4、自定义cell的小知识点

#pragma mark 模版提高的方法
/**   初始化方法
 使用代码创建cell的时候会被调用;若使用xib或者storyBoard创建cell控件的话,此方法不会被调用


 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];//继承父类信息
    if (self) {
        //设置个性信息
    }
    return self;
}


/**
 Prepares the receiver for service after it has been loaded from an Interface Builder archive, or nib file.
 xib文件每次被加载之后,会调用此方法;若使用纯代码创建cell控件的时候,不会调用此方法
 */
- (void)awakeFromNib {
    // Initialization code
}


/**
 Sets the selected state of the cell, optionally animating the transition between states.
 1.cell控件被选中或者取消选中的时候,都会调用此方法
 2.如果是自定义cell,则cell的子控件都应该添加到contentView中
 */
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
    if (selected) {
        [self.contentView setBackgroundColor:[UIColor lightGrayColor]];
    }else{
        [self.contentView setBackgroundColor:[UIColor whiteColor]];
    }

}

cell的frame,由tableView决定(父视图的frame改变的时候,会重新布局子控件)

#pragma mark - setTransform 处理

//Tells the view that its superview changed. 当前的控件加载到父控件(tableview)的时候调用

- (void)didMoveToSuperview{

    NSLog(@"%s 9999",__func__);




    //2.对button的imageView的image进行平移、翻滚--先加载数据,在设置平移

    CGFloat angle = (self.friendsGroup.isOpen) ? M_PI_2 :0;

    [self.titleButtonView.imageView setTransform:CGAffineTransformMakeRotation(angle)];

}




/**当父控件(self)frame发生改变的时候会调用此方法,进行子控件的重新布局  */

- (void)layoutSubviews{

    [self.titleButtonView setFrame:self.bounds];

    CGFloat onlineWidth = 150 ;

    CGFloat onlineX =CGRectGetWidth(self.frame) - onlineWidth - KPading ;

    CGFloat onlineY = KPading ;

    CGFloat onlineHright =CGRectGetHeight(self.frame)- 2*KPading;

    [self.onlineLableView setFrame:CGRectMake(onlineX, onlineY, onlineWidth, onlineHright)];


}

3.2 开发规范

  • 宏的变量名称以项目名前缀开头
  • 本地化设置--针对iOS官方控件

另:CFBundleAllowMixedLocalizations 开启系统预定义的本地化功能

info plist 的配置信息:

<key>CFBundleAllowMixedLocalizations</key>

 <true/>


  • Launch Screen Constraints

The system loads the launch screen file before launching the app which creates some constraints on what it can contain (some of which may force you back to static image files): The app is not yet loaded so the view hierarchy does not exist and the system can not call any custom view controller setup code you may have in the app (e.g. viewDidLoad) You can only use standard UIKit classes so you can use UIView or UIViewController but not a custom subclass. If you try to set a custom class you will get an Illegal Configuration error in Xcode. The launch screen file can only use basic UIKit views such as UIImageView and UILabel. You cannot use a UIWebView. If you are using a storyboard you can specify multiple view controllers but there are again some limitations. For example you can embed view controllers in a navigation or tab bar controller but more complex container classes such as UISplitViewController do not work (at least not yet). Localizing the launch screen file does not currently seem to have any effect. The base localization is always used so you will probably want to avoid text on the launch screen. You cannot specify different launch screen files for iPad and iPhone. This may be a problem if you have significantly different interfaces for those devices as there is only so much you can do with auto layout and size classes.

另:640 × 960 pixels、640 × 1136 pixels。 如果不设置这两种的尺寸启动页的话,在4英寸、3.5英寸的设备上展示不了启动页,app 的高度也默认都是矮的960px.

• 注意@3x 提供给开发的px 为12422208 ,但真实的px 是10801920,系统API会自动进行等比例缩小;

  • 判断对象的class

//        [self isMemberOfClass:]// 判断是否为本类  whether the receiver is an instance of a given class.

//    [self isKindOfClass:];//   判断是否为本类 或者子类 whether the receiver is an instance of given class or an instance of any class that inherits from that class.

  • 像素与点的转换:
  • UITabBarController

UITabBarItem view显示的内容由对应子控制器的tabBarItem属性决定

[redVc.tabBarItem setTitle:@"red"];
 redVc.tabBarItem setImage:(UIImage * _Nullable)

3.3 归档的注意事项(NSCoding协议的使用)

使用一个新方法,需明确本方法什么时候调用,以及方法的作用

#import "HSCustomView.h"
@implementation HSCustomView

/*
1、优先级
 2016-04-07 18:51:21.396 20160407-plist方式存储[5546:241416] -[HSCustomView initWithCoder:]

 2016-04-07 18:51:21.398 20160407-plist方式存储[5546:241416] -[HSCustomView awakeFromNib]
2/如果父类也遵守了NSCoding协议,请注意:-
[super encodeWithCode:encode];确保继承的实例变量也能被编码,即也能被归档

p s:--UIView 就是个典型的例子,UIView的子类必学实现initWithCoder:decoder,否则无法继承父类属性。
*/

- (instancetype)initWithCoder:(NSCoder *)aDecoder{

    NSLog(@"%s",__func__);

    self = [super initWithCoder:aDecoder];//实现父类,继承父类属性

    return self;

}




- (void)awakeFromNib{

    NSLog(@"%s",__func__);

}

3.4 其他小知识点

1、 如果第三方库是MRC,通常最简便的方案是:将其打包成静态库直接使用。

2、Bundle

就是资源文件包。我们将许多图片、XIB、文本文件组织在一起,打包成一个Bundle文件。方便在其他项目中引用包内的资源。

Bundle文件的特点:Bundle是静态的,也就是说,我们包含到包中的资源文件作为一个资源包是不参加项目编译的。也就意味着,bundle包中不能包含可执行的文件。它仅仅是作为资源,被解析成为特定的2进制数据。

see also

公号:iOS逆向

举报

相关推荐

0 条评论