1:iOS中的round/ceil/floorf
extern float ceilf(float);extern double ceil(double);extern long double ceill(long double);extern float floorf(float);extern double floor(double);extern long double floorl(longdouble);extern float roundf(float);extern double round(double);extern long double roundl(longdouble);round:如果參數是小數,則求本身的四舍五入。ceil:如果參數是小數,則求最小的整數但不小于本身.floor:如果參數是小數,則求最大的整數但不大于本身. Example:如何值是3.4的話,則3.4 -- round 3.000000 -- ceil 4.000000 -- floor 3.00000
2:對數組進行轉換,把原來二個值轉化成一條的記錄(滿足左右排版布局)
NSMutableArray *mnewArray=[[NSMutableArray alloc]init]; NSArray *nameArray=@[@"1",@"2",@"3",@"4",@"5",@"6"]; int allCount=0; if (nameArray.count%2==1) { //說明是奇數 allCount=nameArray.count; } else { allCount=nameArray.count-1; } for (int i=0; i<allCount; i++) { userModel *userM=[[userModel alloc]init]; userM.leftName=nameArray[i]; i++; if (i!=nameArray.count) { userM.rightName=nameArray[i]; } [mnewArray addObject:userM]; }
3:APP撥打電話完又跳回到APP里,并監聽它的狀態
#import "ViewController.h"#import <CoreTelephony/CTCall.h>#import <CoreTelephony/CTCallCenter.h>@interface ViewController ()<UIAlertViewDelegate>@PRoperty(strong,nonatomic)UIWebView *phoneCallWebView;//電話監聽@property (nonatomic, strong) CTCallCenter * center;@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];}- (IBAction)sdfsdfsdfs:(id)sender { [self directCall]; //監聽電話 __weak typeof(self) weakSelf = self; self.center = [[CTCallCenter alloc] init]; self.center.callEventHandler = ^(CTCall* call) { if ([call.callState isEqualToString:CTCallStateDisconnected]) { NSLog(@"Call has been disconnected"); } else if ([call.callState isEqualToString:CTCallStateConnected]) { NSLog(@"Call has just been connected"); } else if([call.callState isEqualToString:CTCallStateIncoming]) { NSLog(@"Call is incoming"); } else if ([call.callState isEqualToString:CTCallStateDialing]) { //監聽再進入APP時彈出窗 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"AlertViewTest" message:@"message" delegate:weakSelf cancelButtonTitle:@"Cancel" otherButtonTitles:@"OtherBtn",nil]; [alert show]; NSLog(@"call is dialing"); } else { NSLog(@"Nothing is done"); } };}//打電話 結束完自動跳回APP-(void)directCall{ NSString *PhoneNum=@"10086"; NSURL *phoneURL=[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",PhoneNum]]; if (!self.phoneCallWebView) { self.phoneCallWebView=[[UIWebView alloc]initWithFrame:CGRectZero]; } [self.phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];}@end
注意:監聽電話要引入CoreTelephony.framework,跳轉回APP則是通過一個UIWebView實現
4:UIView的layoutSubviews和drawRect方法何時調用
首先兩個方法都是異步執行。layoutSubviews方便數據計算,drawRect方便視圖重繪。
1、init初始化不會觸發layoutSubviews。
1、如果在UIView初始化時沒有設置rect大小,將直接導致drawRect不被自動調用。drawRect 掉用是在Controller->loadView, Controller->viewDidLoad 兩方法之后掉用的.所以不用擔心在 控制器中,這些View的drawRect就開始畫了.這樣可以在控制器中設置一些值給View(如果這些View draw的時候需要用到某些變量 值).
// 將像素point由point所在視圖轉換到目標視圖view中,返回在目標視圖view中的像素值- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;// 將像素point從view中轉換到當前視圖中,返回在當前視圖中的像素值- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;// 將rect由rect所在視圖轉換到目標視圖view中,返回在目標視圖view中的rect- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;// 將rect從view中轉換到當前視圖中,返回在當前視圖中的rect- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;例把UITableViewCell中的subview(btn)的frame轉換到 controllerA中// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個button// 在controllerA中實現:CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];或CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];// 此rc為btn在controllerA中的rect或當已知btn時:CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];或CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];
新聞熱點
疑難解答