iOS开发基础知识--碎片19 

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*480,后来apple 在iPhone 4中采用了名为Retina的显示技术,iPhone 4采用了960x640像素分辨率的显示屏幕。由于屏幕大小没有变,还是3.5英寸,分辨率的提升将iPhone 4的显示分辨率提升至iPhone 3GS的四倍,每英寸的面积里有326个像素。scale属性的值有两个:
scale = 1; 的时候是代表当前设备是320*480的分辨率(就是iphone4之前的设备)
scale = 2; 的时候是代表分辨率为640*960的分辨率// 判断屏幕类型,普通还是视网膜  float scale = [[UIScreen mainScreen] scale];  if (scale == 1) {  bIsRetina = NO;  NSLog(@"普通屏幕");  }else if (scale == 2) {  bIsRetina = YES;  NSLog(@"视网膜屏幕");  }else{  NSLog(@"unknow screen mode !");  }  

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

bundle是一个目录,其中包含了程序会使用到的资源. 这些资源包含了如图像,声音,编译好的代码,nib文件(用户也会把bundle称为plug-in). 对应bundle,cocoa提供了类NSBundle.我们的程序是一个bundle. 在Finder中,一个应用程序看上去和其他文件没有什么区别. 但是实际上它是一个包含了nib文件,编译代码,以及其他资源的目录. 我们把这个目录叫做程序的main bundlebundle中的有些资源可以本地化.例如,对于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磅=二号磅=(像素/96)*72    =(30/96)*72    =22.5磅中文字号VS英文字号(磅)VS像素值的对应关系:
八号=5磅(5pt) ==(5/72)*96=6.67 =6px(像素)
七号=5.5磅 ==(5.5/72)*96=7.3 =7px(像素)
小六=6.5磅 ==(6.5/72)*96=8.67 =8px(像素)
六号=7.5磅 ==(7.5/72)*96=10px(像素)
小五=9磅 ==(9/72)*96=12px(像素)
五号=10.5磅 ==(10.5/72)*96=14px(像素)
小四=12磅 ==(12/72)*96=16px(像素)
四号=14磅 ==(14/72)*96=18.67 =18px(像素)
小三=15磅 ==(15/72)*96=20px(像素)
三号=16磅 ==(16/72)*96=21.3 =21px(像素)
小二=18磅 ==(18/72)*96=24px(像素)
二号=22磅 ==(22/72)*96=29.3 =29px(像素)
小一=24磅 ==(24/72)*96=32px(像素)
一号=26磅 ==(26/72)*96=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(40, 100, 60, 60)];[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=9;可以通过获得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 * 100;  //(定义的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<0){[timer invalidate];timer = nil;return;}nowSeconds--;if(nowSeconds<=0){self.mylable.text = @"正在揭晓...";return;}int m = (int)nowSeconds / 6000;int s = (int)(nowSeconds/100) - m*60;NSString* f1 = s > 9 ? [NSString stringWithFormat:@"%d",s] : [@"0" stringByAppendingFormat:@"%d",s];int ms = nowSeconds % 100;NSString* f2 = ms > 9 ? [NSString stringWithFormat:@"%d",ms] : [@"0" 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(30, 40, 50, 20);[bcView bk_whenTapped:^{NSLog(@"单击响应");}];[bcView bk_whenDoubleTapped:^{NSLog(@"双击响应");}];[bcView bk_whenTouches:1 tapped:3 handler:^{NSLog(@"三击响应");}];[self.view addSubview:bcView];//Controlbtn=[[UIButton alloc]initWithFrame:CGRectMake(70, 70, 50, 50)];[btn setTitle:@"Save" forState:UIControlStateNormal];btn.backgroundColor=[UIColor grayColor];[btn bk_addEventHandler:^(id sender) {NSLog(@"UIControlEventTouchUpInside响应");//判断跟移除响应[self getUIButtonEventHandler];} forControlEvents:UIControlEventTouchUpInside];[self.view addSubview:btn];//UIAlertViewUIAlertView *alertView=[UIAlertView bk_showAlertViewWithTitle:@"弹出窗效果" message:@"你好,请选择" cancelButtonTitle:@"取消" otherButtonTitles:@[@"确定",@"不想选"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {if (buttonIndex==0) {NSLog(@"你选择第一个");}else if(buttonIndex==1){NSLog(@"你选择第二个");}else{NSLog(@"选择其它个");}}];[alertView show];__block NSInteger total=0;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];//UIActionSheetUIActionSheet *myactionSheet=[[UIActionSheet alloc]initWithTitle:@"显示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相关内容的显示" otherButtonTitles:nil];myactionSheet.bk_cancelBlock=^(){NSLog(@"选择取消actionSheet");};[myactionSheet showInView:self.view];//UITextFieldUITextField *myTextField = [[UITextField alloc] init];myTextField.backgroundColor=[UIColor yellowColor];myTextField.frame=CGRectMake(10, 130, 80, 20);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];

转载于:https://www.cnblogs.com/LiLihongqiang/p/5795961.html

iOS开发基础知识--碎片19相关推荐

  1. iOS开发基础知识--碎片44

    iOS开发基础知识--碎片44  iOS开发基础知识--碎片44 1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = ...

  2. iOS开发基础知识--碎片27

     iOS开发基础知识--碎片27 1:iOS中的round/ceil/floorf extern float ceilf(float); extern double ceil(double); ext ...

  3. iOS开发基础知识--碎片37

    iOS开发基础知识--碎片37 iOS开发基础知识--碎片37 iOS开发基础知识--碎片37 1:iOS 使用NJKWebViewProgress做webview进度条 引入头文件: #import ...

  4. iOS开发基础知识--碎片41

    iOS开发基础知识--碎片41 1:UIWebView加载本地的HTML NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *bas ...

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

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

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

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

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

    1:运行程序报the file couldn't be opened because you don't have permission to view it 解决办法:项目->targets- ...

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

    1:iOS SEL的简单总结 SEL就是对方法的一种包装.包装的SEL类型数据它对应相应的方法地址,找到方法地址就可以调用方法 a.方法的存储位置 在内存中每个类的方法都存储在类对象中 每个方法都有一 ...

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

    1:第三方插件SKSTableView在IOS7.1.1出现闪退的问题 解决办法,修改其内部源代码: (NSInteger)subRow { id indexpath = [NSIndexPath c ...

最新文章

  1. setHasOptionsMenu
  2. php中ide快捷键,PhpStorm、WebStorm及其他系列IDE快捷键
  3. hdu3182 状态压缩dp
  4. Citrix Port(常用端口)
  5. 20155313 2016-2017-2 《Java程序设计》第三周学习总结
  6. [Kafka与Spark集成系列三] Spark编程模型
  7. Elasticsearch -- Java High Level REST Client (RestHighLevelClient) 使用说明文档
  8. java 建立一个graphics对象_java – 我应该显式处理Graphics对象吗?
  9. linux telnet mysql_Linux下安装telnet(傻瓜教程)
  10. 剑指offer面试题[5]-从尾到头打印链表
  11. hsrp+route-map 解决多路由器多isp
  12. HTML输入=“文件”接受属性文件类型(CSV)
  13. 我的迅雷资源博客已经开通!
  14. 如何在IIS添加MIME扩展类型
  15. Java和C#的区别
  16. mysql删除视图sql语句_删除视图的sql语句是什么
  17. php报错_STORAGE_WRITE_ERROR_:./Application/Runtime/Cache/Admin/df12aa1edf6tt330187a6514aae4fda4.php
  18. Bouncy Castle使用(一)【开始】
  19. 保研之旅5:上海科技大学信息学院夏令营
  20. 高清电脑壁纸桌面图片|到高图随心换高清图

热门文章

  1. 2020什么牌子蓝牙耳机性价比高?十大高颜值游戏低延迟蓝牙耳机推荐
  2. OAuth2.0系列之使用JWT令牌实践教程(八)
  3. idea中配置rust遇到No Cargo projects found解决方案
  4. 大型WAV文件的播放
  5. Chrome浏览器高级参数
  6. sql 汉字排序规则(笔画、拼音)
  7. ‘井底蛙’与‘墙内人’
  8. Vue实现JSON格式数据预览 插件 vue-json-viewer
  9. Day52_Flume
  10. 为什么渐进式去中心化是区块链最大的希望?