麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

IOS開發基礎知識--碎片19

2019-11-14 18:39:15
字體:
來源:轉載
供稿:網友

 

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 bundleNSBundle *myBundle = [NSBundle mainBundle];一般我們通過這種方法來得到bundle.如果你需要其他目錄的資源,可以指定路徑來取得bundleNSBundle *goodBundle;goodBundle = [NSBundle bundleWithPath:@"~/.myApp/Good.bundle"];一旦我們有了NSBundle 對象,那么就可以訪問其中的資源了// Extension is optionalNSString *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];            //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響應");        //判斷跟移除響應        [self getUIButtonEventHandler];    } forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn];            //UIAlertView    UIAlertView *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];        //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(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];

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 欧美一区二区三区免费观看 | 午夜视 | 免费三级大片 | 久久999久久 | 亚洲无线看 | 亚洲第一视频在线 | 久久久一区二区三区视频 | sesee99| 黄色免费在线电影 | 久久久久久久亚洲精品 | 精品国产专区 | 视频一区二区不卡 | 久久精品国产99国产精品澳门 | 欧美综合成人 | 99激情视频| 北京一级毛片 | 一本一道久久久a久久久精品91 | 国产激情精品一区二区三区 | 亚洲国产视频在线 | 成年免费视频黄网站在线观看 | 撅高 自己扒开 调教 | 成人男女啪啪免费观看网站四虎 | 日韩99 | 中文字幕天堂在线 | 最新在线黄色网址 | 色阁五月| 亚洲婷婷日日综合婷婷噜噜噜 | 欧美性生活区 | 日韩精品久久久久久久电影99爱 | 欧美区在线 | 亚洲欧美国产高清 | 欧产日产国产精品乱噜噜 | 国产一级一片免费播放 | 羞羞视频免费观看网站 | 成人一区二区三区在线 | xxxxhd73国产| 中文字幕在线观看国产 | 久久成人精品视频 | 久久艹国产精品 | 久久久日韩精品一区二区三区 | 草莓视频久久 |