- 使應用不會自動鎖屏。
[UIApplication sharedApplication].idleTimerDisabled=YES;//不自動鎖屏 [UIApplication sharedApplication].idleTimerDisabled=NO;//自動鎖屏
- 程序圖標不加高光效果
iOS程序build到手機上時,默認的桌面圖標是有高亮的光圈效果的。如果您要去掉這一高亮特效,可以在程序的 info.plist 設置Icon already includes gloss effects,值設定爲YES,默認值是NO。程序上傳到App Store 也就不會在圖標上添加高亮特效了。 - 判斷屏幕分辨率
BOOL retina = CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size);
返回true說明當前分辨率是CGSizeMake(640, 960),false則不是 - 遇到類似這樣的錯誤failed to get the task for process XXX
多半是證書問題,project和targets證書都要是可用並且正確的證書才行。 - 出現這樣的問題Property's synthesized getter follows Cocoa naming convention for returning
Property's synthesized getter follows Cocoa naming convention for returning.
今天早上在整理代碼的時候發現瞭如上警告。
在網上查詢後發現,是因爲蘋果在新的編碼,不推薦變量以new、copy等關鍵字開頭。
突然想起來之前也有朋友問過類似的問題。特做以記錄。
也希望大家在以後編碼的時候,能夠多多注意。 - 快速獲取沙盒路徑
#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] - 判斷郵箱是否合法
- (BOOL) validateEmail: (NSString *) candidate { NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}"; NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex]; return [emailTest evaluateWithObject:candidate]; }
- 顯示網絡活動狀態
UIApplication* app = [UIApplication sharedApplication]; app.networkActivityIndicatorVisible = YES; // to stop it, set this to NO
- 顯示一組連續的圖片(類似動畫效果)
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.gif"], nil]; UIImageView *myAnimatedView = [UIImageView alloc]; [myAnimatedView initWithFrame:[self bounds]]; myAnimatedView.animationImages = myImages; myAnimatedView.animationDuration = 0.25; // seconds myAnimatedView.animationRepeatCount = 0; // 0 = loops forever [myAnimatedView startAnimating]; [self addSubview:myAnimatedView]; [myAnimatedView release];
- 頁面切換效果設置
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
可供使用的效果:
UIModalTransitionStyleCoverVertical
UIModalTransitionStyleFlipHorizontal
UIModalTransitionStyleCrossDissolve
UIModalTransitionStylePartialCurl
恢復之前的頁面:
[self dismissModalViewControllerAnimated:YES]; - 爲UIImageView添加單擊事件:
imageView.userInteractionEnabled = YES; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourHandlingCode:)]; [imageView addGestureRecognizer:singleTap];
- 獲取應用版本
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary]; NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"]; NSString*appName =[infoDict objectForKey:@"CFBundleDisplayName"];
iOS零碎小知識
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.