国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

IOS開發(fā)基礎(chǔ)知識(shí)--碎片19

2019-11-14 18:39:15
字體:
供稿:網(wǎng)友

 

1:鍵盤事件順序

UIKeyboardWillShowNotification          // 鍵盤顯示之前UIKeyboardDidShowNotification           // 鍵盤顯示完成后UIKeyboardWillHideNotification          // 鍵盤隱藏之前UIKeyboardDidHideNotification           // 鍵盤消息之后UIKeyboardWillChangeFrameNotification   // 鍵盤大小改變之前UIKeyboardDidChangeFrameNotification    // 鍵盤大小改變之后

 

2:程序報(bào)-[__NSCFDictionary xxx]: unrecognized selector sen

原因就是對(duì)象是一個(gè)字典,所以不能用點(diǎn)語法,postList.slots錯(cuò)誤解決辦法:[postList valueForKey:@"slots"],使用這種語法  valueForKey  就可以了。


3:UIScreen學(xué)習(xí)記錄

UIScreen對(duì)象包含了整個(gè)屏幕的邊界矩形。當(dāng)構(gòu)造應(yīng)用的用戶界面接口時(shí),你應(yīng)該使用該對(duì)象的屬性來獲得推薦的矩形大小,用以構(gòu)造你的程序窗口。CGRect bound = [[UIScreen mainScreen] bounds];  // 返回的是帶有狀態(tài)欄的Rect  CGRect frame = [[UIScreen mainScreen] applicationFrame];  // 返回的是不帶有狀態(tài)欄的Rect  float scale = [[UIScreen mainScreen] scale]; // 得到設(shè)備的自然分辨率  對(duì)于scale屬性需要做進(jìn)一步的說明: 以前的iphone 設(shè)備屏幕分辨率都是320*480,后來apple 在iPhone 4中采用了名為Retina的顯示技術(shù),iPhone 4采用了960x640像素分辨率的顯示屏幕。由于屏幕大小沒有變,還是3.5英寸,分辨率的提升將iPhone 4的顯示分辨率提升至iPhone 3GS的四倍,每英寸的面積里有326個(gè)像素。scale屬性的值有兩個(gè):scale = 1; 的時(shí)候是代表當(dāng)前設(shè)備是320*480的分辨率(就是iphone4之前的設(shè)備)scale = 2; 的時(shí)候是代表分辨率為640*960的分辨率// 判斷屏幕類型,普通還是視網(wǎng)膜      float scale = [[UIScreen mainScreen] scale];      if (scale == 1) {          bIsRetina = NO;          NSLog(@"普通屏幕");      }else if (scale == 2) {          bIsRetina = YES;          NSLog(@"視網(wǎng)膜屏幕");      }else{          NSLog(@"unknow screen mode !");      }  

 

4:IOS開發(fā)NSBundle對(duì)象使用詳解

bundle是一個(gè)目錄,其中包含了程序會(huì)使用到的資源. 這些資源包含了如圖像,聲音,編譯好的代碼,nib文件(用戶也會(huì)把bundle稱為plug-in). 對(duì)應(yīng)bundle,cocoa提供了類NSBundle.我們的程序是一個(gè)bundle. 在Finder中,一個(gè)應(yīng)用程序看上去和其他文件沒有什么區(qū)別. 但是實(shí)際上它是一個(gè)包含了nib文件,編譯代碼,以及其他資源的目錄. 我們把這個(gè)目錄叫做程序的main bundlebundle中的有些資源可以本地化.例如,對(duì)于foo.nib,我們可以有兩個(gè)版本: 一個(gè)針對(duì)英語用戶,一個(gè)針對(duì)法語用戶. 在bundle中就會(huì)有兩個(gè)子目錄:English.lPRoj和French.lproj,我們把各自版本的foo.nib文件放到其中. 當(dāng)程序需要加載foo.nib文件時(shí),bundle會(huì)自動(dòng)根據(jù)所設(shè)置的語言來加載.通過使用下面的方法得到程序的main bundleNSBundle *myBundle = [NSBundle mainBundle];一般我們通過這種方法來得到bundle.如果你需要其他目錄的資源,可以指定路徑來取得bundleNSBundle *goodBundle;goodBundle = [NSBundle bundleWithPath:@"~/.myApp/Good.bundle"];一旦我們有了NSBundle 對(duì)象,那么就可以訪問其中的資源了// Extension is optionalNSString *path = [goodBundle pathForImageResource:@"Mom"];NSImage *momPhoto = [[NSImage alloc] initWithContentsOfFile:path];bundle中可以包含一個(gè)庫(kù). 如果我們從庫(kù)得到一個(gè)class, bundle會(huì)連接庫(kù),并查找該類:Class newClass = [goodBundle classNamed:@"Rover"];id newInstance = [[newClass alloc] init];如果不知到class名,也可以通過查找主要類來取得Class aClass = [goodBundle principalClass];id anInstance = [[aClass alloc] init];可以看到, NSBundle有很多的用途.在這章中, NSBundle負(fù)責(zé)(在后臺(tái))加載nib文件. 我們也可以不通過NSWindowController來加載nib文件, 直接使用NSBundle:BOOL successful = [NSBundle loadNibNamed:@"About" owner:someObject];注意噢, 我們指定了一個(gè)對(duì)象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設(shè)計(jì)ios App字體以像素為單位,而ios開發(fā)人員寫代碼的時(shí)候是以磅為單位,請(qǐng)問像素與磅之間的換算30px轉(zhuǎn)成磅為單位=22磅=二號(hào)磅=(像素/96)*72    =(30/96)*72    =22.5磅中文字號(hào)VS英文字號(hào)(磅)VS像素值的對(duì)應(yīng)關(guān)系:八號(hào)=5磅(5pt) ==(5/72)*96=6.67 =6px(像素)七號(hào)=5.5磅 ==(5.5/72)*96=7.3 =7px(像素)小六=6.5磅 ==(6.5/72)*96=8.67 =8px(像素)六號(hào)=7.5磅 ==(7.5/72)*96=10px(像素)小五=9磅 ==(9/72)*96=12px(像素)五號(hào)=10.5磅 ==(10.5/72)*96=14px(像素)小四=12磅 ==(12/72)*96=16px(像素)四號(hào)=14磅 ==(14/72)*96=18.67 =18px(像素)小三=15磅 ==(15/72)*96=20px(像素)三號(hào)=16磅 ==(16/72)*96=21.3 =21px(像素)小二=18磅 ==(18/72)*96=24px(像素)二號(hào)=22磅 ==(22/72)*96=29.3 =29px(像素)小一=24磅 ==(24/72)*96=32px(像素)一號(hào)=26磅 ==(26/72)*96=34.67 =34px(像素)

 

6:UIButton一些細(xì)節(jié)問題

// 能夠定義的button類型有以下6種,// typedef enum {// UIButtonTypeCustom = 0, 自定義風(fēng)格// UIButtonTypeRoundedRect, 圓角矩形 // UIButtonTypeDetailDisclosure, 藍(lán)色小箭頭按鈕,主要做詳細(xì)說明用// UIButtonTypeInfoLight, 亮色感嘆號(hào)// UIButtonTypeInfoDark, 暗色感嘆號(hào)// UIButtonTypeContactAdd, 十字加號(hào)按鈕// } UIButtonType;/* forState: 這個(gè)參數(shù)的作用是定義按鈕的文字或圖片在何種狀態(tài)下才會(huì)顯現(xiàn)*///以下是幾種狀態(tài)// enum {// UIControlStateNormal = 0, 常規(guī)狀態(tài)顯現(xiàn) // UIControlStateHighlighted = 1 << 0, 高亮狀態(tài)顯現(xiàn) // UIControlStateDisabled = 1 << 1, 禁用的狀態(tài)才會(huì)顯現(xiàn)// UIControlStateSelected = 1 << 2, 選中狀態(tài) // UIControlStateApplication = 0x00FF0000, 當(dāng)應(yīng)用程序標(biāo)志時(shí) // UIControlStateReserved = 0xFF000000 為內(nèi)部框架預(yù)留,可以不管他 // };/** 默認(rèn)情況下,當(dāng)按鈕高亮的情況下,圖像的顏色會(huì)被畫深一點(diǎn),如果這下面的這個(gè)屬性設(shè)置為no,* 那么可以去掉這個(gè)功能*/button1.adjustsImageWhenHighlighted = NO;/*跟上面的情況一樣,默認(rèn)情況下,當(dāng)按鈕禁用的時(shí)候,圖像會(huì)被畫得深一點(diǎn),設(shè)置NO可以取消設(shè)置*/button1.adjustsImageWhenDisabled = NO;/* 下面的這個(gè)屬性設(shè)置為yes的狀態(tài)下,按鈕按下會(huì)發(fā)光*/button1.showsTouchWhenHighlighted = YES;長(zhǎng)按事件實(shí)例:UIButton *aBtn=[UIButton buttonWithType:UIButtonTypeCustom];    [aBtn setFrame:CGRectMake(40, 100, 60, 60)];    [aBtn setBackgroundImage:[UIImage imageNamed:@"111.png"]forState:UIControlStateNormal];    //button點(diǎn)擊事件    [aBtn addTarget:self action:@selector(btnShort:)forControlEvents:UIControlEventTouchUpInside];    //button長(zhǎng)按事件    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:selfaction:@selector(btnLong:)];     longPress.minimumPressDuration = 0.8; //定義按的時(shí)間    [aBtn addGestureRecognizer:longPress];-(void)btnLong:(UILongPressGestureRecognizer*)gestureRecognizer{    if ([gestureRecognizer state] == UIGestureRecognizerStateBegan) {        NSLog(@"長(zhǎng)按事件");        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"消息" message:@"確定刪除該模式嗎?" delegate:selfcancelButtonTitle:@"取消" otherButtonTitles:@"刪除", nil];        [alert show];    }}

 

7:UIApplication知識(shí)點(diǎn)

UIApplication對(duì)象,這個(gè)對(duì)象在iOS中是一個(gè)單例,我們通過[UIApplication sharedApplication]獲得,設(shè)置顯示消息數(shù),顯示在應(yīng)用程序圖標(biāo)右上角,[UIApplication sharedApplication].applicationIconBadgeNumber=9;可以通過獲得NSIntger x=[UIApplication sharedApplication].applicationIconBadgeNumber; 防止屏幕睡眠:[UIApplication sharedApplication].idleTimerDisabled=YES; 設(shè)置狀態(tài)欄樣式在app delegate中:[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

 

8:一個(gè)倒計(jì)時(shí)的功能代碼

#import "ViewController.h"@interface ViewController (){    NSTimer     *timer;    NSInteger   nowSeconds;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];        nowSeconds = 30 * 100;  //(定義的30秒進(jìn)行倒計(jì))    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插件運(yùn)用

引入#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(@"單擊響應(yīng)");    }];    [bcView bk_whenDoubleTapped:^{        NSLog(@"雙擊響應(yīng)");    }];    [bcView bk_whenTouches:1 tapped:3 handler:^{        NSLog(@"三擊響應(yīng)");    }];    [self.view addSubview:bcView];            //Control    btn=[[UIButton alloc]initWithFrame:CGRectMake(70, 70, 50, 50)];    [btn setTitle:@"Save" forState:UIControlStateNormal];    btn.backgroundColor=[UIColor grayColor];    [btn bk_addEventHandler:^(id sender) {        NSLog(@"UIControlEventTouchUpInside響應(yīng)");        //判斷跟移除響應(yīng)        [self getUIButtonEventHandler];    } forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn];            //UIAlertView    UIAlertView *alertView=[UIAlertView bk_showAlertViewWithTitle:@"彈出窗效果" message:@"你好,請(qǐng)選擇" cancelButtonTitle:@"取消" otherButtonTitles:@[@"確定",@"不想選"] handler:^(UIAlertView *alertView, NSInteger buttonIndex) {        if (buttonIndex==0) {            NSLog(@"你選擇第一個(gè)");        }        else if(buttonIndex==1)        {            NSLog(@"你選擇第二個(gè)");        }        else        {            NSLog(@"選擇其它個(gè)");        }    }];    [alertView show];            __block NSInteger total=0;    UIAlertView *otherAlertView=[[UIAlertView alloc]bk_initWithTitle:@"動(dòng)態(tài)增加" 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:@"系統(tǒng)自帶的alertview" message:@"顯示信息" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];    showAlert.bk_cancelBlock=^()    {        NSLog(@"取消響應(yīng)");    };    showAlert.bk_willShowBlock = ^(UIAlertView *view) { NSLog(@"顯示之前響應(yīng)");};    showAlert.bk_didShowBlock = ^(UIAlertView *view) { NSLog(@"顯示出彈出窗響應(yīng)"); };    [showAlert show];        //UIActionSheet    UIActionSheet *myactionSheet=[[UIActionSheet alloc]initWithTitle:@"顯示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相關(guān)內(nèi)容的顯示" otherButtonTitles:nil];    myactionSheet.bk_cancelBlock=^()    {        NSLog(@"選擇取消actionSheet");    };    [myactionSheet showInView:self.view];            //UITextField    UITextField *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];

 


發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 苍梧县| 临朐县| 大新县| 滨州市| 云浮市| 鹤壁市| 额敏县| 棋牌| 伊金霍洛旗| 临邑县| 迁西县| 集安市| 赞皇县| 隆林| 葫芦岛市| 丽水市| 哈尔滨市| 岚皋县| 乌兰浩特市| 聂拉木县| 庐江县| 卓资县| 自贡市| 芦山县| 蒙自县| 商洛市| 寿光市| 屏东市| 南岸区| 平安县| 都昌县| 鄂伦春自治旗| 昌吉市| 墨江| 江津市| 化州市| 新邵县| 宁远县| 文水县| 封丘县| 姚安县|