標籤:style blog http io ar os 使用 sp for
http://blog.sina.com.cn/s/articlelist_1935098904_1_1.html
、擷取全域的Delegate對象,這樣我們可以調用這個對象裡的方法和變數:
[(MyAppDelegate*)[[UIApplication sharedApplication] delegate] MyMethodOrMyVariable];
2、獲得程式的主Bundle:
NSBundle *bundle = [NSBundle mainBundle];
Bundle可以理解成一種檔案夾,其內容遵循特定的架構。
Main Bundle一種主要用途是使用程式中的資源檔,片、聲音、plst檔案等。
NSURL *plistURL = [bundle URLForResource:@"plistFile" withExtension:@"plist"];
上面的代碼獲得plistFile.plist檔案的路徑。
3、在程式中播放聲音:
首先在程式添加AudioToolbox:
其次,在有播放聲音方法的.m方法添加#import:
#import
接下來,播放聲音的代碼如下:
NSString *path = [[NSBundle mainBundle] pathForResource:@"soundFileName" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID ((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
AudioServicesPlaySystemSound (soundID);
4、設定和擷取類中屬性值:
[self setValue: 變數值 forKey: 變數名];
[self valueForKey: 變數名];
5、讓某一方法在未來某段時間之後執行:
[self performSelector:@selector(方法名) withObject:nil afterDelay:延遲時間(s)];
6、獲得裝置版本號碼:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
7、捕捉程式關閉或者進入後台事件:
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillResignActive:) name:UIApplicationWillResignActiveNotification object:app];
applicationWillResignActive:這個方法中添加想要的操作
8、查看裝置支援的字型:
for (NSString *family in [UIFont familyNames]) {
NSLog(@"%@", family);
for (NSString *font in [UIFont fontNamesForFamilyName:family]) {
NSLog(@"\t%@", font);
}
}
9、為UIImageView添加單擊事件:
imageView.userInteractionEnabled = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)];
[imageView addGestureRecognizer:singleTap];
10、添加多語言支援: 比如Image Picker這樣的組件,它上面的按鈕的文字是隨著裝置語言環境的改變而改變的,但是要先在工程添加語言:
11、使程式支援iTunes這樣的裝置,比如可以使用PC端的工具往程式的Documents中拖放檔案。
12、頁面轉場效果設定:
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
可供使用的效果:
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
恢複之前的頁面:
[self dismissModalViewControllerAnimated:YES];
iOS開發:小技巧積累2