IOS开发基础知识--碎片27
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=@[@"",@"",@"",@"",@"",@""];
int allCount=;
if (nameArray.count%==) {
//说明是奇数
allCount=nameArray.count;
}
else
{
allCount=nameArray.count-;
}
for (int i=; 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=@"";
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。
3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化。
4、滚动一个UIScrollView会触发layoutSubviews。
5、旋转Screen会触发父UIView上的layoutSubviews事件。
6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件。
1、如果在UIView初始化时没有设置rect大小,将直接导致drawRect不被自动调用。drawRect 掉用是在Controller->loadView, Controller->viewDidLoad 两方法之后掉用的.所以不用担心在 控制器中,这些View的drawRect就开始画了.这样可以在控制器中设置一些值给View(如果这些View draw的时候需要用到某些变量 值).
3、通过设置contentMode属性值为UIViewContentModeRedraw。那么将在每次设置或更改frame的时候自动调用drawRect:。
4、直接调用setNeedsDisplay,或者setNeedsDisplayInRect:触发drawRect:,但是有个前提条件是rect不能为0。
以上1,2推荐;而3,4不提倡
2、若使用calayer绘图,只能在drawInContext: 中(类似鱼drawRect)绘制,或者在delegate中的相应方法绘制。同样也是调用setNeedDisplay等间接调用以上方法
3、若要实时画图,不能使用gestureRecognizer,只能使用touchbegan等方法来掉用setNeedsDisplay实时刷新屏幕
// 将像素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];
6:设置谷歌地图ZOOM等级的几种方式
GMSCameraPosition *cameraPosition = [GMSCameraPosition cameraWithLatitude:latitude
longitude:longitude
zoom:11.0]; [self.mapView animateToCameraPosition:cameraPosition];
or GMSCameraUpdate *update = [GMSCameraUpdate zoomTo:11.0];
[self.mapView animateWithCameraUpdate:update];
or [self.mapView animateToZoom:11.0];
IOS开发基础知识--碎片27的更多相关文章
- IOS开发基础知识碎片-导航
1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...
- IOS开发基础知识--碎片33
1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...
- IOS开发基础知识--碎片42
1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...
- IOS开发基础知识--碎片50
1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...
- IOS开发基础知识--碎片3
十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...
- IOS开发基础知识--碎片11
1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...
- IOS开发基础知识--碎片14
1:ZIP文件压缩跟解压,使用ZipArchive 创建/添加一个zip包 ZipArchive* zipFile = [[ZipArchive alloc] init]; //次数得zipfilen ...
- IOS开发基础知识--碎片16
1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...
- IOS开发基础知识--碎片19
1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...
随机推荐
- alert()与console.log()的区别
[1]alert() [1.1]有阻塞作用,不点击确定,后续代码无法继续执行 [1.2]alert()只能输出string,如果alert输出的是对象会自动调用toString()方法 e.g. al ...
- 一起学微软Power BI系列-官方文档-入门指南(1)Power BI初步介绍
我们在前一篇文章微软新神器-Power BI,一个简单易用,还用得起的BI产品中,我们初步介绍了Power BI的基本知识.由于Power BI是去年开始微软新发布的一个产品,虽然已经可以企业级应用, ...
- Android sendevent/getevent 用法
前言:最近在弄一个模拟用户点击屏幕的功能,并且不需要用户点击屏幕,后台自动给输入框赋值,类似pc端按键精灵的功能,在网上找了很多人的资料,写的都不是太详细,一知半解.还要自己慢慢研究.于是我这边写一篇 ...
- BFC之清除浮动篇&clear
我们在日常代码生活中,或多或少会利用浮动来布局,例如导航布局,如下图所示: 但是,我们在实现的时候,经常会遇到父元素“塌陷”以及清除浮动问题.例如 <!DOCTYPE html> < ...
- Util应用程序框架公共操作类(八):Lambda表达式公共操作类(二)
前面介绍了查询的基础扩展,下面准备给大家介绍一些有用的查询封装手法,比如对日期范围查询,数值范围查询的封装等,为了支持这些功能,需要增强公共操作类. Lambda表达式公共操作类,我在前面已经简单介绍 ...
- How to implement a neural network
神经网络的实践笔记 link: http://peterroelants.github.io/posts/neural_network_implementation_part01/ 1. 生成训练数据 ...
- 如何在Windows Server 2008 上添加RD (远程桌面)会话主机配置的远程桌面授权服务器
在Windows Server系列的现存活跃产品中都默认的会开放两个随机附送的远程控制的授权,而一些特殊条件下我们需要启用多个远程终端连接,在购买了相应的授权之后,我们如何将配置好的服务器添加到远程桌 ...
- CSS3中border-radius、box-shadow与gradient那点事儿
一.border-radius border-radius用于添加圆角边框,用处非常广泛. 1)一个值,代表了四个角 .radius-one { /* Safari 3-4, iOS 1-3.2, A ...
- 简析将shp导入Oracle并利用geoserver将导入的数据发布
文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.环境准备 1.1 软件准备 首先要安装有支持空间数据的Oracle ...
- Linux服务器(Ubuntu14.04)添加远程连接VNC Server
1.打开终端输入:sudo apt-get install xrdp, 2. sudo apt-get install vnc4server , 3. sudo apt-get install ...