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

iPhone開發(fā)中一些使用小技巧

移動(dòng)開發(fā) iOS
本文介紹的是iPhone開發(fā)中一些使用小技巧,很詳細(xì)的介紹了,在開發(fā)過程中提高效率的一些小知識(shí),我們來看詳細(xì)內(nèi)容。

iPhone開發(fā)中一些使用小技巧是本文要介紹的內(nèi)容,與友們分享一篇對(duì)編程友人有用的一篇文章,我們來看內(nèi)容。

經(jīng)過半年多的iphone開發(fā),我發(fā)現(xiàn)在開發(fā)過程中最難的就是一些嘈雜的細(xì)節(jié),而了解一些小技巧就會(huì)達(dá)到事半功倍的效果,下面我就總結(jié)一下在iphone開發(fā)中的一些小技巧。

1、如果在程序中想對(duì)某張圖片進(jìn)行處理的話(得到某張圖片的一部分)可一用以下代碼:

  1. UIImage *image = [UIImage imageNamed:filename];  
  2. CGImageRef imageimageRef = image.CGImage;  
  3.  
  4. CGRect rect = CGRectMake(origin.x, origin.y ,size.width, size.height);  
  5.  
  6. CGImageRef imageRefRect = CGImageCreateWithImageInRect(imageRef, rect);  
  7.  
  8. UIImage *imageRect = [[UIImage alloc] initWithCGImage:imageRefRect]; 

2、判斷設(shè)備是iphone還是iphone4的代碼:

  1. #define isRetina ([UIScreen instancesRespondToSelector:  
  2. @selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960),   
  3. [[UIScreen mainScreen] currentMode].size) : NO) 

3、判斷郵箱輸入的是否正確:

  1. - (BOOL) validateEmail: (NSString *) candidate {  
  2. NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";   
  3. NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];   
  4. return [emailTest evaluateWithObject:candidate];  

4、如何把當(dāng)前的視圖作為照片保存到相冊(cè)中去:

  1. #import <QuartzCore/QuartzCore.h> 
  2. UIGraphicsBeginImageContext(currentView.bounds.size);     //currentView 當(dāng)前的view  
  3. [currentView.layer renderInContext:UIGraphicsGetCurrentContext()];  
  4. UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();  
  5. UIGraphicsEndImageContext();  
  6. UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil); 

5、本地通知(類似于push通知)按home鍵到后臺(tái)十秒后觸發(fā):

  1. UILocalNotification *notification=[[UILocalNotification alloc] init];   
  2. if (notification!=nil) {   
  3. NSLog(@">> support local notification");   
  4. NSDate *now=[NSDate new];   
  5. notification.fireDate=[now addTimeInterval:10];   
  6. notification.timeZone=[NSTimeZone defaultTimeZone];   
  7. notification.alertBody=@"該去吃晚飯了!";   
  8. [[UIApplication sharedApplication].scheduleLocalNotification:notification];  

6、捕獲iphone通話事件:

  1. CTCallCenter *center = [[CTCallCenter alloc] init];  
  2. center.callEventHandler = ^(CTCall *call)   
  3. {  
  4. NSLog(@"call:%@", call.callState);  

7、iOS 4 引入了多任務(wù)支持,所以用戶按下 “Home” 鍵以后程序可能并沒有退出而是轉(zhuǎn)入了后臺(tái)運(yùn)行。如果您想讓應(yīng)用直接退出,最簡單的方法是:在 info-plist 里面找到 Application does not run in background 一項(xiàng),勾選即可。

8、使UIimageView的圖像旋轉(zhuǎn):

  1. float rotateAngle = M_PI;  
  2. CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);  
  3. imageView.transform = transform; 

9、設(shè)置旋轉(zhuǎn)的原點(diǎn):

  1. #import <QuartzCore/QuartzCore.h> 
  2. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];  
  3. imageView.layer.anchorPoint = CGPointMake(0.5, 1.0); 

10、實(shí)現(xiàn)自定義的狀態(tài)欄(遮蓋狀態(tài)欄):

  1. CGRect frame = {{0, 0}, {320, 20}};  
  2. UIWindow* wd = [[UIWindow alloc] initWithFrame:frame];  
  3. [wd setBackgroundColor:[UIColor clearColor]];  
  4. [wd setWindowLevel:UIWindowLevelStatusBar];  
  5. frame = CGRectMake(100, 0, 30, 20);  
  6. UIImageView* img = [[UIImageView alloc] initWithFrame:frame];  
  7. [img setContentMode:UIViewContentModeCenter];  
  8. [img setImage:[UIImage imageNamed:@"00_0103.png"]];  
  9. [wd addSubview:img];  
  10. [wd makeKeyAndVisible];  
  11. [UIView beginAnimations:nil context:nil];  
  12. [UIView setAnimationDuration:2];  
  13. frame.origin.x += 150;  
  14. [img setFrame:frame];  
  15. [UIView commitAnimations]; 

11、在程序中實(shí)現(xiàn)電話的撥打:

  1. //添加電話圖標(biāo)按鈕   
  2. UIButton *btnPhone = [[UIButton buttonWithType:UIButtonTypeCustom] retain];   
  3. btnPhone.frame = CGRectMake(280,10,30,30);   
  4. UIImage *image = [UIImage imageNamed:@"phone.png"];       
  5. [btnPhone setBackgroundImage:image forState:UIControlStateNormal];   
  6. //點(diǎn)擊撥號(hào)按鈕直接撥號(hào)   
  7. [btnPhone addTarget:self action:@selector(callAction:event:) forControlEvents:UIControlEventTouchUpInside];   
  8. [cell.contentView addSubview:btnPhone];  //cell是一個(gè)UITableViewCell   
  9. //定義點(diǎn)擊撥號(hào)按鈕時(shí)的操作   
  10. - (void)callAction:(id)sender event:(id)event{   
  11. NSSet *touches = [event allTouches];   
  12. UITouch *touch = [touches anyObject];   
  13. CGPoint currentTouchPosition = [touch locationInView:self.listTable];   
  14. NSIndexPath *indexPath = [self.listTable indexPathForRowAtPoint: currentTouchPosition];   
  15. if (indexPath == nil) {   
  16. return;   
  17. }   
  18. NSInteger section = [indexPath section];   
  19. NSUInteger row = [indexPath row];   
  20. NSDictionary *rowData = [datas objectAtIndex:row];   
  21. NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",number]; //number為號(hào)碼字符串       
  22. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]]; //撥號(hào)   

12、更改iphone的鍵盤顏色:

1.只有這2種數(shù)字鍵盤才有效果。UIKeyboardTypeNumberPad,UIKeyboardTypePhonePad

2. keyboardAppearance = UIKeyboardAppearanceAlert

  1. - (void)textViewDidBeginEditing:(UITextView *)textView{  
  2. NSArray *ws = [[UIApplication sharedApplication] windows];  
  3. for(UIView *w in ws){  
  4. NSArray *vs = [w subviews];  
  5. for(UIView *v in vs)  
  6. {  
  7. if([[NSString stringWithUTF8String:object_getClassName(v)] isEqualToString:@"UIKeyboard"])  
  8. {  
  9. v.backgroundColor = [UIColor redColor];  
  10. }  
  11. }  

13、設(shè)置時(shí)區(qū)

  1. NSTimeZone *defaultTimeZone = [NSTimeZone defaultTimeZone];  
  2. NSTimeZone *tzGMT = [NSTimeZone timeZoneWithName:@"GMT"];  
  3. [NSTimeZone setDefaultTimeZone:tzGMT]; 

上面兩個(gè)時(shí)區(qū)任意用一個(gè)。

14、Ipad隱藏鍵盤的同時(shí)觸發(fā)方法。

  1. [[NSNotificationCenter defaultCenter] addObserver:self  
  2. selector:@selector(keyboardWillHide:)  
  3. name:UIKeyboardWillHideNotification  
  4.   object:nil];  
  5. - (IBAction)keyboardWillHide:(NSNotification *)note 

15、計(jì)算字符串的字?jǐn)?shù)

  1. -(int)calculateTextNumber:(NSString *)text  
  2. {  
  3. float number = 0.0;  
  4. int index = 0;  
  5. for (index; index < [text length]; index++)  
  6. {  
  7. NSString *protoText = [text substringToIndex:[text length] - index];  
  8. NSString *toChangetext = [text substringToIndex:[text length] -1 -index];  
  9. NSString *charater;  
  10. if ([toChangetext length]==0)  
  11. {  
  12. charater = protoText;  
  13. }  
  14. else   
  15. {  
  16. NSRange range = [text rangeOfString:toChangetext];  
  17. charater = [protoText stringByReplacingCharactersInRange:range withString:@""];  
  18. }  
  19. NSLog(charater);  
  20. if ([charater lengthOfBytesUsingEncoding:NSUTF8StringEncoding] == 3)  
  21. {  
  22. number++;  
  23. }  
  24. else   
  25. {  
  26. numbernumber = number+0.5;  
  27. }  
  28. }  
  29. return ceil(number);  
  30. }  

小結(jié):iPhone開發(fā)中一些使用小技巧的內(nèi)容介紹為完了,希望本文對(duì)你有所幫助!

責(zé)任編輯:zhaolei 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2013-03-29 09:03:59

iOS實(shí)用小代碼iOS開發(fā)

2012-12-24 14:51:02

iOS

2015-08-17 15:53:58

Linux桌面

2024-03-11 15:08:26

Linux操作系統(tǒng)進(jìn)程

2011-10-26 20:55:43

ssh 安全

2022-02-17 13:58:38

Linux技巧文件

2021-10-12 23:10:58

UnsafeJavaJDK

2018-09-11 16:15:36

Vue高版本前端

2020-09-25 08:28:12

Javascript

2022-08-28 23:51:04

編輯器vim代碼

2013-07-18 16:16:51

2013-08-21 13:47:29

PhoneUDIDUUID

2009-05-29 09:30:10

iPhone蘋果移動(dòng)OS

2022-05-24 12:50:58

Pandas索引代碼

2017-05-23 14:33:46

簡歷求職前端開發(fā)

2009-11-17 17:15:21

路由器安全設(shè)置

2019-11-22 10:10:46

IT工具技術(shù)

2012-05-21 10:13:05

XCode調(diào)試技巧

2013-03-29 13:17:53

XCode調(diào)試技巧iOS開發(fā)

2011-06-01 16:50:21

JAVA
點(diǎn)贊
收藏

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