IOS開發(fā)

  • 重置密碼
    http://sc.chinaz.com/info/140328474587.htm

  • CocoaPods第三方庫管理
    http://www.360doc.com/content/14/0309/10/11029609_358970353.shtml

  • 布局庫
    https://github.com/SnapKit/Masonry

  • 循環(huán)引用,無法釋放
    self ws

  • 獲取設(shè)備id
    https://github.com/ylechelle/OpenUDID

  • 用pod添加一個(gè)第三方庫的步驟
    庫的地址:https://github.com/ylechelle/OpenUDID
    終端里輸入命令
    用pod搜索,若能搜到就能用pod管理:pod search OpenUDID
    cd到項(xiàng)目的根目錄
    pod install --verbose --no-repo-update

  • 使用linq的庫
    LinqToObjectiveC

  • dictionary轉(zhuǎn)class的庫
    Mantle

  • copy和strong的區(qū)別
    @property (nonatomic, strong)
    @property (nonatomic, copy)

  • ios證書
    鑰匙串->證書->導(dǎo)出
    .p12文件

  • ios中view自適應(yīng)鍵盤的出現(xiàn),不會(huì)出現(xiàn)鍵盤擋住輸入框的情況
    加入第三方庫IQKeyboardManager
    pod 'IQKeyboardManager', '~> 3.2.0.3'

  • tableViewCell的自定義
    一般一個(gè)頁面里就一個(gè)tableView,因?yàn)槎鄠€(gè)tableView并不是一起滑動(dòng)操作的
    一個(gè)tableView里分多個(gè)塊(section)

  • app程序啟動(dòng)上面都有黑底邊
    可以設(shè)置一下app的launch image,如果實(shí)在不需要,那就設(shè)置成全黑圖片

  • mac上的svn版本管理工具
    cornerstone

  • 證書配置
    新環(huán)境開始時(shí),需要用真機(jī)測(cè)試
    apple developer后臺(tái)添加了真機(jī)uid后
    本地增加.p12證書,xcode選擇team,developer后臺(tái)下載Provisioning Profiles文件
    本地雙擊了對(duì)應(yīng)的.mobileprovision文件后,項(xiàng)目的Build Settings,Code Signing Identity中要選擇一下

  • 收起軟鍵盤
    textView輸入時(shí),自動(dòng)彈出的軟鍵盤,想要點(diǎn)擊其他地方就可以收起軟鍵盤
    收起軟鍵盤的方法有:textView resignFirstResponder

  • 截獲點(diǎn)擊事件的方法有:
    // 聲明點(diǎn)擊事件 UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)]; [self.view addGestureRecognizer:tapGesture]; // 自定義點(diǎn)擊處理 -(void)Actiondo:(id)sender { // 注銷當(dāng)前view(或它下屬的text fields)的first responder狀態(tài) [self.view endEditing:YES]; }

  • 素材圖片的扣取
    打開對(duì)應(yīng)界面的psd,如果寬度640,扣出來的原大小素材圖片就是2x大小,再縮小一倍大小就是1x
    找到對(duì)應(yīng)素材位置的圖層(要選中那個(gè)圖層,一般可以通過切換對(duì)應(yīng)圖層前面的眼睛圖標(biāo)來回切換是否顯示圖層來確定是否選擇中缺),用選擇工具框中,復(fù)制到另一個(gè)新地方(ctrl+N)
    在新的地方,選擇 圖像->裁剪,選擇透明像素,就可以去除多余的地方
    保存為web用格式

  • NSDictionary初始化
    鍵值不可以為整數(shù),可以轉(zhuǎn)換成NSNumber

  • ios多線程
    搜gcd

  • 點(diǎn)擊事件帶坐標(biāo)
    普通的addTarget,對(duì)應(yīng)的action方法,參數(shù)是 (id)sender
    換成
    UITapGestureRecognizer* tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)]; [self.btn addGestureRecognizer:tapGesture]; //給自己的btn增加了一個(gè)新類型的點(diǎn)擊處理事件 -(void)Actiondo:(UITapGestureRecognizer *)sender { CGPoint = [sender locationInView:self.view]; }

  • 手機(jī)端調(diào)用的api版本
    服務(wù)端api,地址中可以帶上版本號(hào),以同時(shí)滿足各版本的請(qǐng)求
    例如:http://www.xxx.com/api/myproject/version7/gettopics.php

  • 綁定的數(shù)據(jù)刷新
    例如TableView、CollectionView等,可以通過reloadData來刷新數(shù)據(jù)

  • 顯示png出現(xiàn)不透明,例如黃邊的問題
    UIImageView設(shè)置背景色backgroundColor=[UIColor clearColor]

  • UICollectionView橫向cell間距,會(huì)出現(xiàn)多10
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; [layout setSectionInset:UIEdgeInsetsMake(0,0,0,0)]; [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal]; [layout setMinimumInteritemSpacing:3]; // 橫向間距 [layout setMinimumLineSpacing:0]; // 只是單行橫向也要設(shè)置 [layout setItemSize:CGSizeMake(30,30)]; self.collectionView = [[UICollectionVIew alloc] initWithFrame:CGRectMake(0,0,320,40) collectionViewLayout:layout];

  • 獲取tableView的偏移量
    self.tableView.contentOffset

  • 單擊事件后獲取sender
    [self.btn addTarget:self action:@selector(actionClick:) forControlEvents:UIControlEventTouchUpInside]; -(void)actionClick:(id)sender { UIButton *btn = (UIButton*)sender; }

  • 調(diào)試看值
    可以鼠標(biāo)停在變量上,彈出信息
    如果不彈出,可以在下方輸出信息框的 藍(lán)色的(lldb)后,輸入 po self.array 回車 來打印出self.array的值
    po就是print object的意思

  • 使用gcd多線程獲取數(shù)據(jù)同時(shí)更新UI,但UI刷新不及時(shí)
    如果使用的不是主線程來獲取數(shù)據(jù)(例如dispatch_async(dispatch_get_global_queue)),那么寫在一起的用于更新UI的代碼也是在非主線程中的
    所以如果要及時(shí)更新UI,在非主線程的調(diào)用中,寫一個(gè)主線程更新UI(dispatch_async(dispatch_get_main_queue))

  • ControllerView之間發(fā)送通知
    參數(shù):
    NSDictionary* userInfo = @{@"key1":@"val1"};
    發(fā)送:
    [NSNotificationCenter defaultCenter] postNotificationName:@"唯一的通知名" object:nil userInfo:userInfo];
    接收者們:
    [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MyCallBack:) name:@"唯一的通知名" object:nil]; -(void)MyCallBack:(NSNotification *)notification { NSDictionary *userInfo = notification.userInfo; }

  • 異步網(wǎng)絡(luò)請(qǐng)求處理方式之一
    無參數(shù)時(shí):ASIHTTPRequest
    有參數(shù)時(shí):ASIFormDataRequest

  • 系統(tǒng)自帶的alertView
    UIAlertView *myAlert = [UIAlertView alloc] initWithTitle:@"這里是提示語" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"確定",nil]; [myAlert show]; //實(shí)現(xiàn)那個(gè)delegate -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // buttonIndex 對(duì)應(yīng)上面的按鈕index:0-取消 1-確定 }

  • cell中使用到了sd_setImage結(jié)果出現(xiàn)了殘影
    問題不在sd_setImage,而是在cell重用時(shí),沒有先設(shè)置imageView setImage=nil,然后再用sd_setImage

  • 編輯框,編輯時(shí)的軟鍵盤彈不出來了
    如果是使用的 [textView becomeFirstResponder],來設(shè)置編輯框變成用戶輸入的第一響應(yīng)者,來達(dá)成彈出軟鍵盤的效果
    需要注意,該textView是否在不經(jīng)意間被設(shè)置成了不可編輯狀態(tài)(比如鍵盤類型切換時(shí),文字/表情),使他不能被設(shè)置為響應(yīng)者
    解決辦法是注意在上一次軟鍵盤收起的時(shí)候,設(shè)置textView.editable = YES 還原編輯框的可編輯狀態(tài)

  • UITapGestureRecognizer 與 tableview collectionView等的選中事件沖突時(shí)
    重寫UIGestureRecognizerDelegate委托
    可以判斷[touch.view class]
    但是如果這個(gè)tableView里面的cell使用了自定義的樣式里面包好了UIView等等的話,就無法通過view的class來判斷了
    可以給self.view這個(gè)背景view添加一個(gè)tag,然后判斷touch.view.tag是否是這個(gè)tag就可以判斷出來了

  • UIView動(dòng)畫
    [UIView beginAnimations:nil context:nil]; // 開始動(dòng)畫 [UIView setAnimationDuration:10.0]; // 動(dòng)畫時(shí)長 CGPoint point = _imageView.center; point.y += 150; // 向下移動(dòng) [_imageView setCenter:point]; [UIView commitAnimations]; // 提交動(dòng)畫

  • cell里使用Masonry布局庫布局,mas_makeConstraints沒有生效或受影響
    可能是cell復(fù)用時(shí),make沒有生效的原因
    解決辦法是改用mas_remakeConstraints

  • 使用Masonry布局后,使用UIView animation來做動(dòng)畫,發(fā)現(xiàn)動(dòng)畫不自然(控件從四周聚集起來的樣子),或沒有生效
    因?yàn)閍utolayout和動(dòng)畫有沖突,需要我們手動(dòng)的立即刷新一下控件的位置(在動(dòng)畫前,在動(dòng)畫結(jié)束后,各刷新一下)
    WS(ws); // 起始位置 [self.backVIew mas_remakeConstraints:^(MASConstraintMaker *make){ make.top.equalTo(ws.mas_bottom).with.offset(0); make.left.equalTo(ws.mas_left).with.offset(0); make.right.equalTo(ws.mas_right).with.offset(0); }]; // 動(dòng)畫前立即刷新一下 [self.backView setNeedsLayout]; [self.backView layoutIfNeeded]; // 動(dòng)畫 [UIView animateWithDuration:0.5f animations:^{ [self.backView mas_updateConstraints:^(MASConstraintMaker *make){ make.top.equalTo(ws.mas_bottom).with.offset(-300); // 注意這里只能對(duì)在起始位置設(shè)置過的屬性進(jìn)行修改 }]; // 動(dòng)畫后立即刷新一下 [self.backView setNeedsLayout]; [self.backView layoutIfNeeded]; }];

  • 隱藏頂部欄StatusBar
    一般使用 [[UIApplication sharedApplication] setStatusBarHidden:YES]; 即可
    還一種方法,是修改當(dāng)前window的級(jí)別 self.window.windowLevel = UIWindowLevelStatusBar;
    LevelStatusBar要大于LevelNormal,所以會(huì)顯示在上面

  • 服務(wù)端返回json,app解析出來的emoji表情出現(xiàn)了問題
    app解析json,有下面兩種方式
    // 方式1(這種方式解析出來的emoji可能會(huì)出現(xiàn)問題) NSData *data = [request responseData]; // (ASIHTTPRequest *)request NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSDictionary *dic = [str JSONValue]; // 方式2(這樣的解析在某些時(shí)候可以替代方式1) NSData *data = [request responseData]; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

  • UIButton同時(shí)設(shè)置圖片和文字
    btn setImage
    btn setTitle
    間距:btn setTitleEdgeInsets(文字)

  • UITableView style
    UITableViewStylePlain:
    section header會(huì)固定;
    heightForHeaderInSection設(shè)置0有效;
    UITableVIewStyleGrouped:
    section header不會(huì)固定;
    heightForHeaderInSection設(shè)置0無效;

  • 獲取app版本號(hào)
    NSBundle *bundle = [NSBundle bundleForClass:[self class]]; [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; // 4.9.2 [bundle objectForInfoDictionaryKey:@"CFBundleVerion"]; // 16

  • cell中的btn點(diǎn)擊后,獲取點(diǎn)擊到的是哪個(gè)cell
    -(void)btnClick:(id)sender { CGPoint btnPosition = [sender convertPoint:CGPointZero toView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:btnPosition]; }

  • ios中獲取時(shí)間戳
    long nowTime = [[NSDate date] timeIntervalSince1970];

  • app從后臺(tái)返回來時(shí)執(zhí)行的函數(shù)
    appdelegate中的 -(void)applicationDidBecomeActive:(UIApplication *)application{}

  • 設(shè)置圓角不生效
    UIView.layer.cornerRedius = 12; // 設(shè)置了圓角度數(shù)
    UIView.layer.masksToBounds = YES; // 這里要設(shè)置一下

  • tableview插入新row時(shí)的動(dòng)畫效果
    [itmes addObject:new_row]; // 如果你是用一個(gè)items數(shù)組來存放所有row的數(shù)據(jù)的話 [tableView setContentSize:CGSizeMake(tableView.contentSize.width,tableView.contentSize.height+row_height)] // 為新row增加顯示的空間 [tableView beginUpdates]; [tableView insertRowsAtIndexPaths:[NSIndexPath indexPathForRow:0 inSection:0] withRowAnimation:UITableViewRowAnimationNone]; // 插入新row [tableView endUpdates]; [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[items count]-1 inSection:0 atScrollPosition:UITableViewScrollPositionNona animated:NO]] // 定位到

  • 單個(gè)controller可以注冊(cè)監(jiān)聽app從后臺(tái)返回來的事件
    [NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myfunc) name:UIApplicationWillEnterForegroundNotification object:nil];

  • 用戶標(biāo)識(shí)之一
    \#define IDFA [[[ASIdentifierManager sharedManager] advertisingIdentifier] UUIDString]

  • 判斷是否安裝了某應(yīng)用,是否打開它
    NSURL *appSchemeUrl = [NSURL URLWithString:@"yourapp://"];if ([[UIApplication sharedApplication] canOpenURL:appSchemeUrl]) { [[UIApplication sharedApplication] openURL:appSchemeUrl]; }else{ NSURL *appStoreUrl = [NSURL URLWithString:@"itms-apps://itunes.apple.com/cn/app/yourid"]; if ([[UIApplication sharedApplication] canOpenURL:appStoreUrl]) { [[UIApplication sharedApplication] openURL:appStoreUrl]; } }

  • 單例的使用
    User.h: @interface User:NSObject +(User*)shareInstance; @end User.m: static id _instance; @implementation User +(User*)shareInstance { static dispatch_once_t once; dispatch_once(&once,^{_instance = [[self alloc] init];}); return _instance; } @end 調(diào)用的時(shí)候: [User shareInstance];

  • [NSUserDefaults standarUserDefaults] setObject setValue不能放long之類的數(shù)值
    用[NSNumber numberWithLong]之類的,用NSNumber包裝一下

  • NSString 轉(zhuǎn)成 int,0的轉(zhuǎn)換會(huì)有問題
    [@"0" intValue] = nil

  • 監(jiān)控手勢(shì)操作
    UISwipeGestureRecognizer *recognizer = [UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; recognizer.direction = UISwipeGestureRecognizerDirectionRight; [self.view addGestureRecognizer:recognizer]; -(void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer{ if(recognizer.direction == UISwipeGestureRecognizerDirectionRight) { [self back]; // 這個(gè)例子是右滑手勢(shì)的返回功能 } } -(void)back{ [self.nacigationController popViewControllerAnimated:YES]; }

  • 自定義Framework
    可打出模擬器專用framework,真機(jī)專用framework
    要打出通用性的framework,需要合并兩個(gè)framework
    可以在自定義framework項(xiàng)目中,添加Run Script,每次Run時(shí)執(zhí)行一個(gè)腳本來自動(dòng)生成
    if [ "${ACTION}" = "build" ]thenINSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}.frameworkDEVICE_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphoneos/${PROJECT_NAME}.frameworkSIMULATOR_DIR=${BUILD_ROOT}/${CONFIGURATION}-iphonesimulator/${PROJECT_NAME}.frameworkif [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"#ditto "${DEVICE_DIR}/Headers" "${INSTALL_DIR}/Headers"lipo -create "${DEVICE_DIR}/${PROJECT_NAME}" "${SIMULATOR_DIR}/${PROJECT_NAME}" -output "${INSTALL_DIR}/${PROJECT_NAME}"#open "${DEVICE_DIR}"#open "${SRCROOT}/Products"fi

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容