IOS開發基礎知識--碎片13

1:運行程序報the file couldn't be opened because you don't have permission to view it?

解決辦法:項目—>targets->build settings->build options->changed the value of the "Compiler for C/C++/Objective-C" to Default Compiler. 

2:百度地圖引用

1.1如圖引用的是.framework形式開發包時,引入的命名空間則是
#import <BaiduMapAPI/BMapKit.h>//引入所有的頭文件
#import <BaiduMapAPI/BMKMapView.h>//只引入所需的單個頭文件
如果是引入用的是.a形式開發包時,引入的命名空間則是
#import “BMapKit.h"

1.2百度地圖現在提供的兩個.framework的包,一個是真機一個是測試機,可以使用終端的命令把它合成一個;

3:自定義大頭針百度地圖

- (void)viewDidLoad {[super viewDidLoad];//百度地圖初始化_mapView=[[BMKMapView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-NAVBARHEIGHT)];_mapView.delegate=self;[self.view addSubview:_mapView];//標出坐標點
    [self addPointAnnotation];
}//添加標注
- (void)addPointAnnotation
{for (int i=0; i<self.coordinates.count; i++) {coordinateBean *model=self.coordinates[i];BMKPointAnnotation* pointAnnotation = [[BMKPointAnnotation alloc]init];CLLocationCoordinate2D coor;coor.latitude = model.latitude;coor.longitude = model.longitude;pointAnnotation.coordinate = coor;//通過title來起到傳值的作用pointAnnotation.title=[NSString stringWithFormat:@"%d",i];[_mapView addAnnotation:pointAnnotation];//顯示彈出窗
        [_mapView selectAnnotation:pointAnnotation animated:YES];//判斷那個是中心,沒有則0必傳參數if (i==self.selectIndex) {BMKCoordinateRegion region; ////表示范圍的結構體region.center.latitude  = model.latitude;// 中心中region.center.longitude = model.longitude;region.span.latitudeDelta = 0;//經度范圍(設置為0.1表示顯示范圍為0.2的緯度范圍)region.span.longitudeDelta = 0;//緯度范圍
            [_mapView setRegion:region];}}
}
//處理自定義彈出視圖
- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation
{if ([annotation isKindOfClass:[BMKPointAnnotation class]]) {BMKPinAnnotationView *newAnnotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"myrenameMark"];newAnnotationView.pinColor = BMKPinAnnotationColorPurple;newAnnotationView.animatesDrop = YES;// 設置該標注點動畫顯示
       newAnnotationView.image = [UIImage imageNamed:self.mapPointImageName];   //把大頭針換成別的圖片int selectIndex=[((BMKPointAnnotation *)annotation).title intValue];//獲得值coordinateBean *model=[self.coordinates objectAtIndex:[((BMKPointAnnotation *)annotation).title intValue]];UIView *popView=[[UIView alloc]initWithFrame:CGRectMake(0, 3, 100, 20)];UIImage *img=[UIImage imageNamed:@"mapViewBackground"];UIEdgeInsets edge=UIEdgeInsetsMake(0, 20, 0, 10);img=[img resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];UIImageView *myimage=[[UIImageView alloc] initWithImage:img];myimage.frame=CGRectMake(30, 0, 100, 40);myimage.userInteractionEnabled=YES;[popView addSubview:myimage];//自定義顯示的內容UILabel *driverName = [[UILabel alloc]initWithFrame:CGRectMake(0, 3, 100, 15)];driverName.backgroundColor=[UIColor clearColor];driverName.text=model.title;driverName.font = [UIFont systemFontOfSize:12];driverName.textColor = [UIColor blackColor];driverName.textAlignment = NSTextAlignmentLeft;[myimage addSubview:driverName];UILabel *carName = [[UILabel alloc]initWithFrame:CGRectMake(0, 18, 100, 15)];carName.backgroundColor=[UIColor clearColor];carName.text=model.comments;carName.font = [UIFont systemFontOfSize:12];carName.textColor = [UIColor blackColor];carName.textAlignment = NSTextAlignmentLeft;[myimage addSubview:carName];BMKActionPaopaoView *pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];pView.frame = CGRectMake(0, 0, 100, 40);((BMKPinAnnotationView*)newAnnotationView).paopaoView = nil;((BMKPinAnnotationView*)newAnnotationView).paopaoView = pView;newAnnotationView.tag=selectIndex+10;return newAnnotationView;}return nil;
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}
/***  @author wujunyang, 15-05-12 13:05:05**  @brief  跟對百度地圖的處理*  @param animated <#animated description#>*/
-(void)viewWillAppear:(BOOL)animated
{[_mapView viewWillAppear];_mapView.delegate=self;_locationService.delegate=self;
}
/***  @author wujunyang, 15-01-06 10:01:53**  跟對百度地圖的處理**  @param animated <#animated description#>*/
-(void)viewWillDisappear:(BOOL)animated
{[_mapView viewWillDisappear];_mapView.delegate=nil;_locationService.delegate=nil;
}其中有個自定義model:@interface coordinateBean : NSObject
//緯度
@property(assign,nonatomic)float latitude;
//經度
@property(assign,nonatomic)float longitude;
//標題
@property(strong,nonatomic)NSString *title;
//注解
@property(strong,nonatomic)NSString *comments;
@end

?4:自動隱藏和顯示工具欄和導航條

toolbar屬性、toolbarItems與上一講的navigationBar、navigationItem類似。只不過toolbarItems沒有navigationItem的左右區分,它就自己一個人在做事,相當于沒有下屬。可以在toolbar上設置很多,比如背景顏色、背景圖片、背景樣式、大小位置(不過有些貌似設置無效),當然和navigationBar一樣,對于它的是否顯示和隱藏是由它的老爸即navigationController控制的。所以[self.navigationController setNavigationBarHidden:YES animated:YES];也會把底部的toolBarItems給隱藏起來,如果要隱藏導航又不想底部toolBarItems被隱藏掉,可以用普通的view替代toolBarItems;首先在viewDidLoad里設置toolBarHidden = NO, 默認是YES(隱藏的)為了讓toolbar顯示,需要設置為NO(不隱藏)。- (void)viewDidLoad
{[super viewDidLoad];self.title = @"隱藏導航欄";// self.toolbarItemsself.navigationController.toolbar.barStyle = self.toolBar.barStyle;self.navigationController.toolbarHidden = NO;[self.navigationController.toolbar setTranslucent:YES];self.toolbarItems = [[[NSMutableArray alloc] initWithArray:self.toolBar.items] autorelease];
}在點擊中間button的時候的顯示和隱藏navigation bar和toolBar實現代碼如下:- (IBAction)toggleNavigationBar:(id)sender
{//Check the current state of the navigation bar...BOOL navBarState = [self.navigationController isNavigationBarHidden];//Set the navigationBarHidden to the opposite of the current state.[self.navigationController setNavigationBarHidden:!navBarState animated:YES];[self.navigationController setToolbarHidden:!navBarState animated:YES];//Change the label on the button.if (navBarState){[button setTitle:@"隱藏 Navigationr and toolbar" forState:UIControlStateNormal];[button setTitle:@"隱藏 Navigation Bar toolbar" forState:UIControlStateHighlighted];}else{[button setTitle:@"顯示 Navigation Bar toolbar" forState:UIControlStateNormal];[button setTitle:@"顯示 Navigation Bar toolbar" forState:UIControlStateHighlighted];}
}

5:View代碼結構的一些建議

在viewDidload里面只做addSubview的事情,然后在viewWillAppear里面做布局的事情,最后在viewDidAppear里面做Notification的監聽之類的事情。至于屬性的初始化,則交給getter去做。@interface CustomObject()
@property (nonatomic, strong) UILabel *label;
@end@implement#pragma mark - life cycle- (void)viewDidLoad
{[super viewDidLoad];[self.view addSubview:self.label];
}- (void)viewWillAppear:(BOOL)animated
{[super viewWillAppear:animated];self.label.frame = CGRectMake(1, 2, 3, 4);
}#pragma mark - getters and setters- (UILabel *)label
{if (_label == nil) {_label = [[UILabel alloc] init];_label.text = @"1234";_label.font = [UIFont systemFontOfSize:12];... ...}return label;
}
@end注意:*重點,在get方法里面不能寫self.noLabel;千萬不要用“點”語法,這樣會造成get方法死循環,因為“點”語法就是調用的get方法,所以要用下劃線屬性名的方法得到對象(在內存這其實是一個指針)。
@interface MasonryViewController ()
@property(nonatomic,strong)UIView *conView;
@property(nonatomic,assign)int intstate;
@end@implementation MasonryViewController- (void)viewDidLoad {[super viewDidLoad];[self.view addSubview:self.conView];
}
//懶加載
-(UIView *)conView
{if(_conView==nil){_conView=[[UIView alloc]init];_conView.backgroundColor=[UIColor redColor];}return _conView;
}-(int)intstate
{_intstate=0;return _intstate;
}//布局約束
-(void)viewDidLayoutSubviews
{[self.conView mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(self.view.mas_top).with.offset(100);make.left.equalTo(self.view.mas_left).with.offset(60);make.right.equalTo(self.view.mas_right).with.offset(0);make.height.equalTo(@50);}];
}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];
}

?

6: iOS中的生成隨機數方法

生成0-x之間的隨機正整數int value =arc4random_uniform(x + 1);生成隨機正整數int value = arc4random() 通過arc4random() 獲取0到x-1之間的整數的代碼如下:int value = arc4random() % x; 獲取1到x之間的整數的代碼如下: int value = (arc4random() % x) + 1; 最后如果想生成一個浮點數,可以在項目中定義如下宏:#define ARC4RANDOM_MAX      0x100000000 然后就可以使用arc4random() 來獲取0到100之間浮點數了(精度是rand()的兩倍),代碼如下:double val = floorf(((double)arc4random() / ARC4RANDOM_MAX) * 100.0f);實例(從數組中隨機顯示出一個背景圖,再通過網絡加載顯示出來):self.bgView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];self.bgView.image=[UIImage imageNamed:@"AppBg"];[self.view addSubview:self.bgView];[self.view sendSubviewToBack:self.bgView];NSDictionary *params=[[NSDictionary alloc] init];[[HomeMainNetAPIManager sharedManager] getBackgroundImage:params andBlock:^(id data, NSError *error) {if (!error&&data) {BackgroundImageBean *groundImagebean =(BackgroundImageBean *)data;int dataNum=groundImagebean.data.count;if (groundImagebean.data&&dataNum>0) {int r=arc4random_uniform(dataNum);GroundImageBean *curBean=groundImagebean.data[r];[self.bgView sd_setImageWithURL:[NSURL URLWithString:curBean.ImgUrl] placeholderImage:[UIImage imageNamed:@"AppBg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {dispatch_async(dispatch_get_main_queue(), ^{self.bgView.image=image;});}];}}}];

7:沙盒路徑知識整理

模擬器的路徑從之前的~/Library/Application Support/iPhone Simulator移動到了~/Library/Developer/CoreSimulator/Devices/文件都在個人用戶名文件夾下的一個隱藏文件夾里,中文叫資源庫,他的目錄其實是Library。因為應用是在沙箱(sandbox)中的,在文件讀寫權限上受到限制,只能在幾個目錄下讀寫文件:
Documents:應用中用戶數據可以放在這里,iTunes備份和恢復的時候會包括此目錄
tmp:存放臨時文件,iTunes不會備份和恢復此目錄,此目錄下文件可能會在應用退出后刪除
Library/Caches:存放緩存文件,iTunes不會備份此目錄,此目錄下文件不會在應用退出刪除iTunes在與iPhone同步時,備份所有的Documents和Library文件。
iPhone在重啟時,會丟棄所有的tmp文件。查看方法:
方法1、可以設置顯示隱藏文件,然后在Finder下直接打開。設置查看隱藏文件的方法如下:打開終端,輸入命名
(1)顯示Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool true
(2)隱藏Mac隱藏文件的命令:defaults write com.apple.finder AppleShowAllFiles -bool false
(3)輸完單擊Enter鍵,退出終端,重新啟動Finder就可以了 重啟Finder:鼠標單擊窗口左上角的蘋果標志-->強制退出-->Finder-->
現在能看到資源庫文件夾了。 
打開資源庫后找到/Application Support/iPhone Simulator/文件夾。這里面就是模擬器的各個程序的沙盒目錄了。
方法2、這種方法更方便,在Finder上點->前往->前往文件夾,輸入/Users/username/Library/Application Support/iPhone Simulator/  前往。
username這里寫用戶名。 自定義類返回各目錄路徑:#import <Foundation/Foundation.h>@interface ICSandboxHelper : NSObject+ (NSString *)homePath;     // 程序主目錄,可見子目錄(3個):Documents、Library、tmp
+ (NSString *)appPath;        // 程序目錄,不能存任何東西
+ (NSString *)docPath;        // 文檔目錄,需要ITUNES同步備份的數據存這里,可存放用戶數據
+ (NSString *)libPrefPath;    // 配置目錄,配置文件存這里
+ (NSString *)libCachePath;    // 緩存目錄,系統永遠不會刪除這里的文件,ITUNES會刪除
+ (NSString *)tmpPath;        // 臨時緩存目錄,APP退出后,系統可能會刪除這里的內容
+ (BOOL)hasLive:(NSString *)path; //判斷目錄是否存在,不存在則創建

實現代碼:#import "ICSandboxHelper.h"@implementation ICSandboxHelper+ (NSString *)homePath{return NSHomeDirectory();
}+ (NSString *)appPath
{NSArray * paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES);return [paths objectAtIndex:0];
}+ (NSString *)docPath
{NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);return [paths objectAtIndex:0];
}+ (NSString *)libPrefPath
{NSArray * paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);return [[paths objectAtIndex:0] stringByAppendingFormat:@"/Preference"];
}+ (NSString *)libCachePath
{NSArray * paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);return [[paths objectAtIndex:0] stringByAppendingFormat:@"/Caches"];
}+ (NSString *)tmpPath
{return [NSHomeDirectory() stringByAppendingFormat:@"/tmp"];
}+ (BOOL)hasLive:(NSString *)path
{if ( NO == [[NSFileManager defaultManager] fileExistsAtPath:path] ){return [[NSFileManager defaultManager] createDirectoryAtPath:pathwithIntermediateDirectories:YESattributes:nilerror:NULL];}return NO;
}

?

轉載于:https://www.cnblogs.com/wujy/p/4503381.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/258919.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/258919.shtml
英文地址,請注明出處:http://en.pswp.cn/news/258919.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《LoadRunner 12七天速成寶典》—第2章2.6節第二個性能測試案例

本節書摘來自異步社區《LoadRunner 12七天速成寶典》一書中的第2章&#xff0c;第2.6節第二個性能測試案例&#xff0c;作者陳霽&#xff0c;更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 2.6 第二個性能測試案例云云&#xff1a;烤魚吃得很爽。 戀戀&#xff1a;就…

MongoDB_1

突然想去看下MongoDB的東西&#xff0c;于是有了這篇文章。其實很早以前就看過一些關于NoSql的文章&#xff0c;還記得當時里面有介紹MongoDB的&#xff0c;多瞅了2眼&#xff0c;并且在Window下安裝了MongoDB的驅動&#xff0c;小玩了會。今天重新翻出來&#xff0c;沒成想在命…

牛頓法與擬牛頓法,SDM方法的一些注記

SDM方法 考慮一般額NLS問題&#xff1a; f(x)minx||h(x)?y||2這里x為優化參數&#xff0c;h為非線性函數&#xff0c;y是已知變量&#xff0c;如下是基于梯度的迭代公式&#xff1a; ΔxαAJTh(h(x)?y)這里α是步長&#xff0c;A是縮放因子&#xff0c;Jh是h在當前參數x下的…

pyqt5從子目錄加載qrc文件_實戰PyQt5: 045-添加資源文件

添加資源文件在使用PyQt進行圖形界面開發的時候不免要用到一些外部資源&#xff0c;比如圖片&#xff0c;qss配置文件等。在前面代碼中&#xff0c;遇到這類問題&#xff0c;我們使用絕對路徑的方式來解決&#xff0c;這種方式&#xff0c;本身有其不方便之處(比如&#xff0c;…

《 Python樹莓派編程》——2.7 總結

本節書摘來自華章出版社《Python樹莓派編程》一書中的第2章&#xff0c;第2.7節&#xff0c;作者&#xff1a;[美]沃爾弗拉姆多納特&#xff08;Wolfram Donat&#xff09;著 韓德強 等譯&#xff0c;更多章節內容可以訪問云棲社區“華章計算機”公眾號查看。 2.7 總結 本章簡…

ACM的輸入輸出總結

關于ACM的輸入輸出&#xff08;一&#xff09; 一般來說ACM的現場賽會規定輸入輸出 或者是文件輸入標準輸出 也可能是文件輸入文件輸出 如果沒有規定的話那么一般就是標準的輸入輸出了 那說一下輸入輸出的重定向 一般用下面兩種方法 c常用: #include <fstream.h>ifstream…

hdu 2064漢諾塔III 遞推

漢諾塔遞推題&#xff0c;比漢諾塔多了一個限制條件&#xff0c;盤子只允許在相鄰的柱子之間移動。 分析&#xff1a; 第1步:初始狀態&#xff1b; 第2步:把上面的n-1個盤移到第3號桿上&#xff1b; 第3步:把第n個盤從1移到2&#xff1b; 第4步:把前n-1個從3移到1&#xff0c;給…

西門子ddc_鐵門關西門子兩通電動閥VVF42.25-10C+SKD60西

鐵門關西門子兩通電動閥西SIEMENS/西門子電動溫控閥、控制箱、電動蝶閥、電動球閥、超聲波熱量表、超聲波流量計、電磁流量計閥體灰口鑄鐵 EN-GJL-2502.霍尼韋爾主營&#xff1a;樓宇資料系統、熱網自控系統、風機盤管電動兩通閥、空氣壓差開關、水流開關、電動執行器、風閥執行…

swap關于指針的使用

先看下面兩個例子&#xff1a; #include <iostream> // std::cout #include <utility> // std::swapint main() {int x 10, y 20; // x:10 y:20int* p1 &x;int* p2 &y;std::swap(*p1, *p2); // x:20 y:10 …

JS-鍵盤事件之方向鍵移動元素

注意三點&#xff1a; 1&#xff1a;事件名稱onkeydown。 2&#xff1a;事件加給document&#xff0c;而非window。 3&#xff1a; 把元素的top&#xff0c;left值分別用offsetTop&#xff0c;offsetLeft來設定。 <!DOCTYPE html> <html><head><meta char…

Swift學習字符串、數組、字典

一.字符串的使用 let wiseWords "\"I am a handsome\"-boy" var emptyString "" if emptyString.isEmpty{ println("這是一個空值") }簡單說明&#xff1a;isEmpty方法是用來判斷字符串是否為空值的&#xff0c;之后會執行if語句中的…

python對excel操作簡書_Python讀寫Excel表格,就是這么簡單粗暴又好用

最近在做一些數據處理和計算的工作&#xff0c;因為數據是以.CSV格式保存的&#xff0c;因此剛開始直接用Excel來處理。 但是做著做著發現重復的勞動&#xff0c;其實并沒有多大的意義&#xff0c;于是就想著寫個小工具幫著處理。 以前正好在一本書上看到過&#xff0c;使用Pyt…

九度 1470 調整方陣

題目描述&#xff1a; 輸入一個N&#xff08;N<10&#xff09;階方陣&#xff0c;按照如下方式調整方陣&#xff1a;1.將第一列中最大數所在的行與第一行對調。2.將第二列中從第二行到第N行最大數所在的行與第二行對調。依此類推...N-1.將第N-1列中從第N-1行到第N行最大數所…

halcon/c++接口基礎 之 halcon初認識

從今天開始&#xff0c;開始更新博客&#xff0c;主要分享自己最近正在翻譯的Halcon/C教程。先給出第一篇文章&#xff0c;由于此文章&#xff0c;是用latex寫的&#xff0c;直接導成html&#xff0c;保存在七牛云存儲上&#xff0c;所以直接點擊鏈接就看到&#xff0c;后面我將…

指數型組織形成的 9 大驅動因素

指數時代&#xff0c;是一個前所未有的激動人心的世界。 Airbnb, 谷歌, 亞馬遜和GitHub這些知名的公司&#xff0c;都有一個讓人稱羨的共同點&#xff0c;那就是——他們都是非常成功的指數型組織&#xff08;Exponential Organizations&#xff0c;ExO’s&#xff09;。 “在當…

Java for LeetCode 061 Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given 1->2->3->4->5->NULL and k 2, return 4->5->1->2->3->NULL. 解題思路&#xff1a; 只需找到對應的位置&#xff0c;然后指向head&…

mysqld:表mysql.plugin不存在_99%測試工程師不知道的數據庫知識|干貨

點擊上方“藍字”關注我們數據庫&#xff0c;簡而言之可視為電子化的文件柜——存儲電子文件的處所&#xff0c;用戶可以對文件中的數據進行新增、查詢、更新、刪除等操作。所謂“數據庫”是以一定方式儲存在一起、能與多個用戶共享、具有盡可能小的冗余度、與應用程序彼此獨立…

Windows Phone 執行模型概述

Windows Phone 執行模型控制在 Windows Phone 上運行的應用程序的生命周期&#xff0c;該過程從啟動應用程序開始&#xff0c;直至應用程序終止。 該執行模型旨在始終為最終用戶提供快速響應的體驗。為此&#xff0c;在任何給定時間內&#xff0c;Windows Phone 僅允許一個應用…

halcon/c++接口基礎 之 構造函數與Halcon算子

Halcon/C提供了構造函數&#xff0c;主要基于適合的Halcon算子。比如說HImage和HBarCode基于read_image and create_bar_code_model。 請注意當前的Halcon版本針對不同的算子構造函數的功能不同。如下我們介紹了一些最常用的Halcon算子&#xff0c;而一個完整的構造函數列表可…

Android Wifi簡單的梳理【轉】

本文轉載自&#xff1a;http://blog.csdn.net/gabbzang/article/details/10005411 代表一個已經配置過的網絡。包含網絡ID(networkId)、該網絡ID代表的網絡的BSSID和SSID、加密機制、密碼等信息。 WifiInfo&#xff1a; 代表一個正在建立或者已經建立的網絡連接。該網絡的BSSID…