自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

iOS開發(fā)之小技巧積累

移動開發(fā) iOS
沒有奇跡,只有努力。我們成長在如此無奈而又相似的人生中,或許我們該真的活一次,即便是失敗,至少這種成就感和真實感是很難得的。通過日積月累的技術(shù)成長,總有一天你也是個大咔。

1、獲取全局的Delegate對象,這樣我們可以調(diào)用這個對象里的方法和變量:

  1. [(MyAppDelegate*)[[UIApplication sharedApplication] delegate] MyMethodOrMyVariable]; 

2、獲得程序的主Bundle:

  1. NSBundle *bundle = [NSBundle mainBundle]; 

Bundle可以理解成一種文件夾,其內(nèi)容遵循特定的框架。

Main Bundle一種主要用途是使用程序中的資源文件,如圖片、聲音、plst文件等。

  1. NSURL *plistURL = [bundle URLForResource:@"plistFile" withExtension:@"plist"]; 

上面的代碼獲得plistFile.plist文件的路徑。

3、在程序中播放聲音:

首先在程序添加AudioToolbox:

其次,在有播放聲音方法的.m方法添加#import:

  1. #import<AudioToolbox/AudioToolbox.h> 

接下來,播放聲音的代碼如下:

  1. NSString *path = [[NSBundle mainBundle] pathForResource:@"soundFileName" ofType:@"wav"];  
  2. SystemSoundID soundID;  
  3. AudioServicesCreateSystemSoundID ((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);  
  4. AudioServicesPlaySystemSound (soundID);  

4、設(shè)置和獲取類中屬性值:

  1. [self setValue: 變量值 forKey: 變量名]; 
  2. [self valueForKey: 變量名]; 

5、讓某一方法在未來某段時間之后執(zhí)行:

  1. [self performSelector:@selector(方法名) withObject:nil afterDelay:延遲時間(s)];  

6、獲得設(shè)備版本號:

  1. float version = [[[UIDevice currentDevice] systemVersion] floatValue]; 

7、捕捉程序關(guān)閉或者進入后臺事件:

  1. UIApplication *app = [UIApplication sharedApplication]; 
  2. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app]; 

applicationWillResignActive:這個方法中添加想要的操作

8、查看設(shè)備支持的字體:

  1. for (NSString *family in [UIFont familyNames]) { 
  2.     NSLog(@"%@", family); 
  3.     for (NSString *font in [UIFont fontNamesForFamilyName:family]) { 
  4.         NSLog(@"\t%@", font); 
  5.     } 

9、為UIImageView添加單擊事件:

  1. imageView.userInteractionEnabled = YES; 
  2. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)]; 
  3. [imageView addGestureRecognizer:singleTap]; 

10、添加多語言支持:
比如Image Picker這樣的組件,它上面的按鈕的文字是隨著設(shè)備語言環(huán)境的改變而改變的,但是要先在工程添加語言:

11、使程序支持iTunes這樣的設(shè)備,比如可以使用PC端的工具往程序的Documents中拖放文件:

12、頁面切換效果設(shè)置:

  1. controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical; 
  2. [self presentModalViewController:controller animated:YES]; 

可供使用的效果:

  1. UIModalTransitionStyleCoverVertical  //新視圖從下向上出現(xiàn) 
  2. UIModalTransitionStyleFlipHorizontal //以設(shè)備的長軸為中心翻轉(zhuǎn)出現(xiàn) 
  3. UIModalTransitionStyleCrossDissolve  //漸漸顯示 
  4. UIModalTransitionStylePartialCurl    //原視圖向上卷起 

恢復(fù)之前的頁面:

  1. [self dismissModalViewControllerAnimated:YES]; 

13、獲取截屏

  1. - (UIImage *)getScreenShot { 
  2.     UIGraphicsBeginImageContext(self.view.bounds.size); 
  3.     [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
  4.     UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
  5.     UIGraphicsEndImageContext(); 
  6.     return image; 
責任編輯:閆佳明 來源: oschina
相關(guān)推薦

2015-03-23 09:44:55

iOS開發(fā)技巧

2014-08-04 17:46:15

NavBarTarBar

2011-02-21 17:15:14

SilverlightNEY

2024-05-07 07:04:05

前端調(diào)試技巧瀏覽器

2013-07-29 04:46:48

iOS開發(fā)iOS開發(fā)學(xué)習(xí)iOS小知識

2013-06-20 11:04:46

iOS技巧NotificatioBadgeView

2015-02-04 10:32:57

Objective-CSwift

2012-08-16 10:35:50

Windows Pho

2023-05-15 08:18:21

CSS技巧代碼

2015-08-10 09:50:21

ios圖片文本

2011-03-23 16:24:44

LAMPMySQL

2024-04-29 08:05:34

NacosJava數(shù)據(jù)結(jié)構(gòu)

2014-07-23 13:17:53

iOSUITextField

2015-07-20 09:16:42

iOSWatchKit開發(fā)

2014-07-21 14:49:35

iOSUILabel

2011-04-02 08:39:27

Visual Stud

2011-08-08 17:05:02

XCode UserScript 腳本

2016-12-28 13:19:08

Android開發(fā)坑和小技巧

2023-01-03 09:00:52

React前端

2015-07-27 09:36:09

storyboard
點贊
收藏

51CTO技術(shù)棧公眾號