1:键盘事件顺序

UIKeyboardWillShowNotification          // 键盘显示之前
UIKeyboardDidShowNotification // 键盘显示完成后
UIKeyboardWillHideNotification // 键盘隐藏之前
UIKeyboardDidHideNotification // 键盘消息之后
UIKeyboardWillChangeFrameNotification // 键盘大小改变之前
UIKeyboardDidChangeFrameNotification // 键盘大小改变之后

2:程序报-[__NSCFDictionary xxx]: unrecognized selector sen

原因就是对象是一个字典,所以不能用点语法,postList.slots错误

解决办法:[postList valueForKey:@"slots"],使用这种语法  valueForKey  就可以了。

3:UIScreen学习记录

UIScreen对象包含了整个屏幕的边界矩形。当构造应用的用户界面接口时,你应该使用该对象的属性来获得推荐的矩形大小,用以构造你的程序窗口。

CGRect bound = [[UIScreen mainScreen] bounds];  // 返回的是带有状态栏的Rect
CGRect frame = [[UIScreen mainScreen] applicationFrame]; // 返回的是不带有状态栏的Rect
float scale = [[UIScreen mainScreen] scale]; // 得到设备的自然分辨率 对于scale属性需要做进一步的说明: 以前的iphone 设备屏幕分辨率都是320*,后来apple 在iPhone 4中采用了名为Retina的显示技术,iPhone 4采用了960x640像素分辨率的显示屏幕。由于屏幕大小没有变,还是3.5英寸,分辨率的提升将iPhone 4的显示分辨率提升至iPhone 3GS的四倍,每英寸的面积里有326个像素。 scale属性的值有两个:
scale = ; 的时候是代表当前设备是320*480的分辨率(就是iphone4之前的设备)
scale = ; 的时候是代表分辨率为640*960的分辨率 // 判断屏幕类型,普通还是视网膜
float scale = [[UIScreen mainScreen] scale];
if (scale == ) {
bIsRetina = NO;
NSLog(@"普通屏幕");
}else if (scale == ) {
bIsRetina = YES;
NSLog(@"视网膜屏幕");
}else{
NSLog(@"unknow screen mode !");
}

4:IOS开发NSBundle对象使用详解

bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.

我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundle

bundle中的有些资源可以本地化.例如,对于foo.nib,我们可以有两个版本: 一个针对英语用户,一个针对法语用户. 在bundle中就会有两个子目录:English.lproj和French.lproj,我们把各自版本的foo.nib文件放到其中. 当程序需要加载foo.nib文件时,bundle会自动根据所设置的语言来加载.通过使用下面的方法得到程序的main bundle
NSBundle *myBundle = [NSBundle mainBundle];
一般我们通过这种方法来得到bundle.如果你需要其他目录的资源,可以指定路径来取得bundle
NSBundle *goodBundle;
goodBundle = [NSBundle bundleWithPath:@"~/.myApp/Good.bundle"];
一旦我们有了NSBundle 对象,那么就可以访问其中的资源了
// Extension is optional
NSString *path = [goodBundle pathForImageResource:@"Mom"];
NSImage *momPhoto = [[NSImage alloc] initWithContentsOfFile:path];
bundle中可以包含一个库. 如果我们从库得到一个class, bundle会连接库,并查找该类:
Class newClass = [goodBundle classNamed:@"Rover"];
id newInstance = [[newClass alloc] init];
如果不知到class名,也可以通过查找主要类来取得
Class aClass = [goodBundle principalClass];
id anInstance = [[aClass alloc] init];
可以看到, NSBundle有很多的用途.在这章中, NSBundle负责(在后台)加载nib文件. 我们也可以不通过NSWindowController来加载nib文件, 直接使用NSBundle:
BOOL successful = [NSBundle loadNibNamed:@"About" owner:someObject];
注意噢, 我们指定了一个对象someObject作为nib的File”s Owner 获取XML文件
NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"re" ofType:@"xml"];
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath]; 获取属性列表
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ViewControllers" ofType:@"plist"]];

5:单位换算,PX换算成磅

用ps设计ios App字体以像素为单位,而ios开发人员写代码的时候是以磅为单位,请问像素与磅之间的换算

30px转成磅为单位=22磅=二号磅=(像素/)*    =(/)*    =.5磅

中文字号VS英文字号(磅)VS像素值的对应关系:
八号=5磅(5pt) ==(/)*=6.67 =6px(像素)
七号=.5磅 ==(5.5/)*=7.3 =7px(像素)
小六=.5磅 ==(6.5/)*=8.67 =8px(像素)
六号=.5磅 ==(7.5/)*=10px(像素)
小五=9磅 ==(/)*=12px(像素)
五号=.5磅 ==(10.5/)*=14px(像素)
小四=12磅 ==(/)*=16px(像素)
四号=14磅 ==(/)*=18.67 =18px(像素)
小三=15磅 ==(/)*=20px(像素)
三号=16磅 ==(/)*=21.3 =21px(像素)
小二=18磅 ==(/)*=24px(像素)
二号=22磅 ==(/)*=29.3 =29px(像素)
小一=24磅 ==(/)*=32px(像素)
一号=26磅 ==(/)*=34.67 =34px(像素)

6:UIButton一些细节问题

// 能够定义的button类型有以下6种,
// typedef enum {
// UIButtonTypeCustom = 0, 自定义风格
// UIButtonTypeRoundedRect, 圆角矩形
// UIButtonTypeDetailDisclosure, 蓝色小箭头按钮,主要做详细说明用
// UIButtonTypeInfoLight, 亮色感叹号
// UIButtonTypeInfoDark, 暗色感叹号
// UIButtonTypeContactAdd, 十字加号按钮
// } UIButtonType; /* forState: 这个参数的作用是定义按钮的文字或图片在何种状态下才会显现*/
//以下是几种状态
// enum {
// UIControlStateNormal = 0, 常规状态显现
// UIControlStateHighlighted = 1 << 0, 高亮状态显现
// UIControlStateDisabled = 1 << 1, 禁用的状态才会显现
// UIControlStateSelected = 1 << 2, 选中状态
// UIControlStateApplication = 0x00FF0000, 当应用程序标志时
// UIControlStateReserved = 0xFF000000 为内部框架预留,可以不管他
// };
/*
* 默认情况下,当按钮高亮的情况下,图像的颜色会被画深一点,如果这下面的这个属性设置为no,
* 那么可以去掉这个功能
*/
button1.adjustsImageWhenHighlighted = NO;
/*跟上面的情况一样,默认情况下,当按钮禁用的时候,图像会被画得深一点,设置NO可以取消设置*/
button1.adjustsImageWhenDisabled = NO;
/* 下面的这个属性设置为yes的状态下,按钮按下会发光*/
button1.showsTouchWhenHighlighted = YES; 长按事件实例: UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[aBtn setFrame:CGRectMake(, , , )];
[aBtn setBackgroundImage:[UIImage imageNamed:@"111.png"]forState:UIControlStateNormal];
//button点击事件
[aBtn addTarget:self action:@selector(btnShort:)forControlEvents:UIControlEventTouchUpInside];
//button长按事件
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:selfaction:@selector(btnLong:)];
longPress.minimumPressDuration = 0.8; //定义按的时间
[aBtn addGestureRecognizer:longPress]; -(void)btnLong:(UILongPressGestureRecognizer*)gestureRecognizer{
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
NSLog(@"长按事件");
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"消息" message:@"确定删除该模式吗?" delegate:selfcancelButtonTitle:@"取消" otherButtonTitles:@"删除", nil];
[alert show];
}
}

7:UIApplication知识点

UIApplication对象,这个对象在iOS中是一个单例,我们通过[UIApplication sharedApplication]获得,

设置显示消息数,显示在应用程序图标右上角,[UIApplication sharedApplication].applicationIconBadgeNumber=;可以通过获得NSIntger x=[UIApplication sharedApplication].applicationIconBadgeNumber; 

防止屏幕睡眠:[UIApplication sharedApplication].idleTimerDisabled=YES; 

设置状态栏样式在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

8:一个倒计时的功能代码

#import "ViewController.h"

@interface ViewController ()
{
NSTimer *timer;
NSInteger nowSeconds;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; nowSeconds = * ; //(定义的30秒进行倒计)
timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerAction) userInfo:nil repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} - (void)timerAction
{
if(nowSeconds<)
{
[timer invalidate];
timer = nil;
return;
}
nowSeconds--;
if(nowSeconds<=)
{
self.mylable.text = @"正在揭晓...";
return;
}
int m = (int)nowSeconds / ;
int s = (int)(nowSeconds/) - m*;
NSString* f1 = s > ? [NSString stringWithFormat:@"%d",s] : [@"" stringByAppendingFormat:@"%d",s];
int ms = nowSeconds % ;
NSString* f2 = ms > ? [NSString stringWithFormat:@"%d",ms] : [@"" stringByAppendingFormat:@"%d",ms];
self.mylable.text = [NSString stringWithFormat:@"0%d:%@:%@",m,f1,f2];
}
@end

9:BlocksKit插件运用

引入#import <BlocksKit/BlocksKit.h>
#import <BlocksKit/BlocksKit+UIKit.h> 常见的一些blocks: //视图
UIView *bcView=[[UIView alloc]init];
bcView.backgroundColor=[UIColor redColor];
bcView.frame=CGRectMake(, , , );
[bcView bk_whenTapped:^{
NSLog(@"单击响应");
}];
[bcView bk_whenDoubleTapped:^{
NSLog(@"双击响应");
}];
[bcView bk_whenTouches: tapped: handler:^{
NSLog(@"三击响应");
}];
[self.view addSubview:bcView]; //Control
btn=[[UIButton alloc]initWithFrame:CGRectMake(, , , )];
[btn setTitle:@"Save" forState:UIControlStateNormal];
btn.backgroundColor=[UIColor grayColor];
[btn bk_addEventHandler:^(id sender) {
NSLog(@"UIControlEventTouchUpInside响应");
//判断跟移除响应
[self getUIButtonEventHandler];
} forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; //UIAlertView
UIAlertView *alertView=[UIAlertView bk_showAlertViewWithTitle:@"弹出窗效果" message:@"你好,请选择" cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定",@"不想选"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {
if (buttonIndex==) {
NSLog(@"你选择第一个");
}
else if(buttonIndex==)
{
NSLog(@"你选择第二个");
}
else
{
NSLog(@"选择其它个");
}
}];
[alertView show]; __block NSInteger total=;
UIAlertView *otherAlertView=[[UIAlertView alloc]bk_initWithTitle:@"动态增加" message:@"是否是要增加"];
NSInteger index1 = [otherAlertView bk_addButtonWithTitle:@"确定" handler:^{ total++;
NSLog(@"%ld",total);
}];
[otherAlertView.bk_dynamicDelegate alertView:otherAlertView clickedButtonAtIndex:index1];
[otherAlertView show]; UIAlertView *showAlert=[[UIAlertView alloc] initWithTitle:@"系统自带的alertview" message:@"显示信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
showAlert.bk_cancelBlock=^()
{
NSLog(@"取消响应");
};
showAlert.bk_willShowBlock = ^(UIAlertView *view) { NSLog(@"显示之前响应");};
showAlert.bk_didShowBlock = ^(UIAlertView *view) { NSLog(@"显示出弹出窗响应"); };
[showAlert show]; //UIActionSheet
UIActionSheet *myactionSheet=[[UIActionSheet alloc]initWithTitle:@"显示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相关内容的显示" otherButtonTitles:nil];
myactionSheet.bk_cancelBlock=^()
{
NSLog(@"选择取消actionSheet");
};
[myactionSheet showInView:self.view]; //UITextField
UITextField *myTextField = [[UITextField alloc] init];
myTextField.backgroundColor=[UIColor yellowColor];
myTextField.frame=CGRectMake(, , , );
myTextField.bk_shouldBeginEditingBlock=^(UITextField *textField) {
NSLog(@"shouldBeginEditingBlock");
return YES;
};
myTextField.bk_shouldBeginEditingBlock = ^(UITextField *textField) { NSLog(@"shouldBeginEditingBlock");
return YES;
};
myTextField.bk_didBeginEditingBlock = ^(UITextField *textField) { NSLog(@"didBeginEditingBlock");
};
myTextField.bk_shouldEndEditingBlock = ^(UITextField *textField) { NSLog(@"shouldEndEditingBlock");
return YES;
};
myTextField.bk_didEndEditingBlock = ^(UITextField *textField) { NSLog(@"didEndEditingBlock ");
};
myTextField.bk_shouldChangeCharactersInRangeWithReplacementStringBlock = ^(UITextField *textField, NSRange range, NSString *replacement) { NSLog(@"shouldChangeCharactersInRangeWithReplacementStringBlock"); return YES;
};
myTextField.bk_shouldClearBlock = ^(UITextField *textField) { NSLog(@"shouldClearBlock");
return YES;
};
myTextField.bk_shouldReturnBlock = ^(UITextField *textField) { NSLog(@"shouldReturnBlock");
return YES;
};
[self.view addSubview:myTextField];

IOS开发基础知识--碎片19的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  3. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  4. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  5. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  6. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  7. IOS开发基础知识--碎片14

    1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片40

    1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...

随机推荐

  1. 4、解析配置文件 redis.conf、Redis持久化RDB、Redis的主从复制

    1.Units单位 配置大小单位,开头定义了一些基本的度量单位,只支持bytes,不支持bit 对大小写不敏感 2.INCLUDES包含 和我们的Struts2配置文件类似,可以通过includes包 ...

  2. Vim 快速上手

    1.vi的基本概念 基本上vi可以分为三种状态,分别是 命令模式(command mode) 插入模式(Insert mode) 底行模式(last line mode) 1) 命令行模式comman ...

  3. Comet ASP.NET AJAX 示例

    最近公司有个项目,里面要求要用到Comet技术,所以就到网上找了一下相关的资料和文章,发现有些人说用Ajax的长轮询比较好,后来就百度了一下,发现comet貌似就是通过ajax演变而来的,也就是com ...

  4. 如何使用Xmanager及VNC登录远程桌面

    如何调用远程桌面,比较常见的有两种方式:Xmanager及VNC 正好今天鼓捣了一下,特整理如下: Xmanager Xmanager的调用也有两种方式: 一.直接在Xshell中调用 这时需设置会话 ...

  5. 小菜学习Winform(二)WMPLib实现音乐播放器

    前言 现在网上有很多的音乐播放器,但好像都不是.net平台做的,在.net中实现音乐文件的播放功能很简单,下面就简单实现下. SoundPlayer类 在.net提供了音乐文件的类:SoundPlay ...

  6. hibernate笔记--双向一对多映射方法

    前两节写了两个例子,分别是单向多对一的映射和单向一对多的映射,这一节继续以这个例子讲一下双向一对多的映射方法,如下图所示: 很多时候,我们既想从一对端获取多对端的信息,又想从多对端获取一对端的数据,这 ...

  7. DotNet项目中的一些常用验证操作

    在项目中需要对用户输入的信息,以及一些方法生成的结果进行验证,一般在项目中较多的采用js插件或js来进行有关信息的校验,但是从项目安全性的角度进行考虑,可对系统进行js注入. 如果在后台对用户输入的信 ...

  8. VS 2010一步步开发windows服务(windows service)

    基于0起步来创建一个服务,做到简单的记录时间日志功能,其具体招行方法可自行添加. 1.创建服务 2.删除默认服务文件 3.添加自己的服务文件 4.更改启动项目 5. 引用 using System.T ...

  9. Hexo主题实现多级分类显示

    前言 最近在搞一个博客,是托管在github和gitcafe上的,利用Hexo生成的.之后,发现一个问题,显示的分类都是一级的.而我想要的是:能显示多级分类,层次分明`的那样. 问题 基本主题自带的分 ...

  10. 【手记】未能从程序集System.Net.Http.Formatting中加载类型System.Net.Http.Formatting.FormUrlEncodedMediaTypeFormatter

    实际报错如图: 如果你跟我一样是在折腾Asp.Net WebApi 2.x时遇到这个问题,请参看如下办法: 删除现有System.Net.Http.Formatting引用(如果引用了的话) 重新引用 ...