一些小知识点(3)

来源:互联网 发布:国外国内四大数据库 编辑:程序博客网 时间:2024/06/02 04:45

作者:Love@YR
链接:http://blog.csdn.net/jingqiu880905/article/details/52055635
请尊重原创,谢谢!

  1. 如何让webview页面不能下拉,不要露出下拉后面的背景和滑到底之后上滑后面的背景?
    self.webView.scrollView.bounces = NO;

  2. vi文件保存退出命令 先按esc键 然后输入:wq ,编辑时删除当前光标所在位置的字符用x,readonly option is set add to override !时用sudo vi 不要用vi

  3. UIWebView中禁止长按响应和放大镜等默认交互行为:
    http://my.oschina.net/hmj/blog/111344
    文中说了两种方法,一种是直接在css里去禁止:

body.disable-default-action{    -webkit-touch-callout:none ;    -webkit-user-select:none ;}

一种是在webViewDidFinishLoad里禁止。
4. 预估行高可以减少行高计算方法被执行的次数

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{  return 60;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  //一大堆代码  return size.height;}

虽然estimatedHeightForRowAtIndexPath也被执行了很多次,但是方法体里直接return 一个定值,不耗时。如果不加入这个方法,heightForRowAtIndexPath就被执行很多次,每次又一大堆代码。
5. 关于build settings里的配置
涉及到路径的,因为此设置是写在工程名.xcodeproj里,所以其他都是在工程名的文件夹里,如Prefix Header :JSCallOC/PrefixHeader.pch
6. debug模式改release模式。edit scheme- run- info build configuration改release,debug executable勾掉。
7. 屏蔽NSLog

#ifdef DEBUG#define NJLog(...) NSLog(__VA_ARGS__)#else#define NJLog(...)#endif

然后在代码里不用NSLog用NJLog,这样在非debug模式下就不会打印log

或者这种:

#define DISABLE_LOG#ifndef DISABLE_LOG#define ENABLE_LOG#endif#if defined(ENABLE_LOG)#define TLog(format, ...) NSLog((@"%s@%d: " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)#define CLog(format, ...) NSLog((@"%s@%d: " format), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)#else#define NSLog(format, ...)#define TLog(format, ...)#define CLog(format, ...)#endif

这个意思就是如果定义了禁止log,那么代码中NSLog就不再打印(还有一些其他你自定义的log)否则NSLog没被重定义,跟debug, release无关。
8. 关于各种空:
首先了解下C语言的各种类型:http://www.cnblogs.com/onedime/archive/2012/11/21/2780149.html
各种空类型参考:
http://blog.csdn.net/tianjf0514/article/details/18054365
http://www.mamicode.com/info-detail-649183.html

nil: NSObject对象空指针
Nil: NSObject类空指针(比如说类存在则是个非Nil的class,不存在则是Nil。就比如initWithNibName:bundle:这个方法,if (self = [super initWithNibName:NULL bundle:NULL]) {。。。})
NULL: 指向其他类型(如:基本类型、C类型int * char 、结构体Ivar 、枚举、id类型(就比如上面的例子的类型就是可能是空也可能是字串,所以用了id类型))的空指针
NSNull:通常表示集合中的空值,为了占位的。不能用空对象。
9. C语言中的const
const char * ch
const在*前面表示这是一个字符串常量指针,它所指向的字符串不能被修改,但是这个指针的指向可以改变,它和char const *ch是一样的,比如:

const char *ch="123";//指向常量字符串123,123的内容不能被修改,但可以改变ch的指向ch="Hello World!";//可以改变ch的指向

如果const在*的后面,则表示这是一个指针常量,它的指向不能被修改,但可以修改批所指向的内容,比如:

char c[] = "123";char * const ch=c;//ch的指向不能被修改,但它所指向的内容视情况可以被修改,//比如由于c是个字符数组,所以,可以通过ch修改c数组的值ch[0]='4';//修改c[0]为4,c变成"423


10. objc_msgSend 报错:use of undeclared identifier ‘objc_msgSend’ 修错方法:#import <objc/message.h>
11. 关于模拟器运行时上下出现很大块黑边:
一般是运行老的代码,老的xcode生成的代码出现这个问题。改成创建一个Launch Screen.storyboard,然后在target那边设置app icons and launch images那里选择Launch Screen File即可~
12. 关于截图
下面这个例子是截某个tableview的前5行(若小于5行则截所有行)的图。(section可能不止一个)

-(void)screenshot:(id)sender{   UIImage *img= [self captureScrollView:self.parentTableView];//拿到图片    UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);//保存到相册}- (UIImage *)captureScrollView:(UITableView *)scrollView{    NSInteger totalRowCount =0;    CGFloat fifthRowMaxY=0;    for (int section = 0; section<_parentTableView.numberOfSections; section++) {        NSInteger rowCountInSection = [_parentTableView numberOfRowsInSection:section];        if (totalRowCount+rowCountInSection<5) {            if (section==_parentTableView.numberOfSections-1) {                NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:rowCountInSection-1 inSection:section];                CGRect rectInTableView = [_parentTableView rectForRowAtIndexPath:cellIndexPath];                fifthRowMaxY = CGRectGetMaxY(rectInTableView);                break;//跳出外层循环            }            totalRowCount+=rowCountInSection;            continue;        }        else{            for (int row=0;row<rowCountInSection; row++) {                NSIndexPath *cellIndexPath = [NSIndexPath indexPathForRow:row inSection:section];                if (totalRowCount+row==5-1) {                    CGRect rectInTableView = [_parentTableView rectForRowAtIndexPath:cellIndexPath];                    fifthRowMaxY = CGRectGetMaxY(rectInTableView);                    break;//跳出内层循环                }            }            break;//跳出外层循环        }    }    UIImage* image = nil;    CGSize size = CGSizeMake(scrollView.contentSize.width, fifthRowMaxY);//不截全部截半截    UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);//画板的高度与内容的高度相同fifthRowMaxY则不会出现多余空白//    UIGraphicsBeginImageContext(scrollView.contentSize);    {        CGPoint savedContentOffset = scrollView.contentOffset;        CGRect savedFrame = scrollView.frame;        scrollView.contentOffset = CGPointZero;        scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, fifthRowMaxY);        NSLog(@"scrollView.contentOffset is %@, scrollView.frame is %@",NSStringFromCGPoint(savedContentOffset),NSStringFromCGRect(scrollView.frame));        [scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];        image = UIGraphicsGetImageFromCurrentImageContext();        //重置为之前的位置        scrollView.contentOffset = savedContentOffset;        scrollView.frame = savedFrame;    }    UIGraphicsEndImageContext();    if (image != nil) {        return image;    }    return nil;}

…..
13. 关于使用autoLayout时有scrollview时如何设定
http://www.cocoachina.com/ios/20141118/10242.html

总结下来就是首先设置scrollview的frame,即其相对于其superview的坐标和宽高,然后重点是scrollview里的subview来定住scrollview的contentview的宽,高。
首先subview的宽高需要定住,而不是设置成相对于scrollview的contentview的宽高
其次scrollview相对于其subview的top,bottom,leading,trailing要有,这样才能定住scrollview的contentview的高度和宽度。如下图:
这里写图片描述
14. ios app的生命周期:
http://blog.csdn.net/totogo2010/article/details/8048652/
15. viewController的生命周期:
http://www.cnblogs.com/xjy-123/p/5271063.html
http://www.cocoachina.com/industry/20121120/5134.html
16. 给工程添加pch文件:
http://www.jianshu.com/p/e6e0e3bbbf38

0 0
原创粉丝点击