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];
新闻热点
疑难解答