MS 以前有出過一個產品,叫做 bob
http://zh.wikipedia.org/wiki/Microsoft_Bob
Microsoft Bob是一個介紹Windows功能的軟體。此軟體具有動畫助手和有趣的圖片,同漫遊 Windows XP 相似。但是,在Bob推出不久,他就在市場上立不了足了。
MS 以前有出過一個產品,叫做 bob
http://zh.wikipedia.org/wiki/Microsoft_Bob
Microsoft Bob是一個介紹Windows功能的軟體。此軟體具有動畫助手和有趣的圖片,同漫遊 Windows XP 相似。但是,在Bob推出不久,他就在市場上立不了足了。
按鈕是個很煩的東西..
背景圖片常沒有明顯邊界
有邊界的又會受限大小
所以可能的話,我一向偏好按鈕用背景圖和 Border
檔案要先 import QuartCore
指令
[btn_pick.layer setBorderColor:[[UIColor redColor] CGColor]];
[btn_pick.layer setBorderWidth:4.0];
btn_pick.layer.cornerRadius = 8.0;
Border 其實是 CALayer 做出來的
這表示所有的 view 基本上都可以套用
BoderColor 吃 CGColorRef, 所以要用 CGColor 方法轉換一下
這工作聽起來很簡單的東西
不過還是碰到了一些小問題
基本工作是設定 HTML 檔案
複製到 xCode 中
如果 html 中有使用目錄的話,這邊要注意選擇 create folder
然後使用以下指令載入
NSURL *indexFileURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
[webView loadRequest:[NSURLRequest requestWithURL:indexFileURL]];
畫面呈現上,要注意一下
HTML 預設會有 40 px 的 padding
進 debug 模式查後,發現有 -webkit-padding-start: 40px; 的預設設定
我的解法是在 html body 中設定另一個替代性 div,然後設定 padding: 0
理論上應該是要放 body {} 中比較完美,但是一直無效(css 苦手...)
先來個簡單的 NSString CString 字串轉換
from http://mobiledevelopertips.com/c/converting-between-c-and-objective-c-strings.html
// NSString object to C
NSString *str = @"String object to a C string";
const char *ptr = [str cStringUsingEncoding:NSUTF8StringEncoding];
printf("%s\n", ptr);
// Another approach with the same result
const char *ptr2 = [str UTF8String];
printf("%s\n", ptr2);
// C string to NSString object
ptr = "C string to string object";
str = [NSString stringWithCString:ptr encoding:NSUTF8StringEncoding];
NSLog(@"%@", str);
然後更進一步,解 \uxxxx
NSString *s = [NSString stringWithUTF8String:"\u53f0\u7063 114 \u53f0\u5317\u5e02 \u65b0\u660e\u8def143\u5df7 4\u865f"];
NSLog(@"%@", s);
接下來是 \U
這邊其實有個問題,\U和\u並不相同
\U 是從 json parse 出來的結果
會處理這問題其實是因為取得資料時碰到一點小問題
如下字串:
\U53f0\U7063 114 \U53f0\U5317\U5e02 \U65b0\U660e\U8def143\U5df7 4\U865f
這組字串是從 CLGeocoder 的 FormattedAddressLines 中取出
原型是 NSArray,網路上的簡單處理方法是直接合併取得字串
NSString* ss = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
不過這一串到底是怎麼來的我還是搞不清楚..
先在此做個註記,日後繼續處理
MKMapview有提供自己的- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated 事件監測地圖移動
唯一缺點是不能檢查是使用者拖動還是程式移動
對我而言,導致的主要問題是第一次進入時就會觸發事件
因為我打算在移動地圖時讓某些元件半透明增加可視區域
這問題會引起一些小小的 UX 遺憾
所以採用了額外的監測方式:
使用 UIGesture 檢查是否為使用者移動,是的話才呼叫程式
一、設定 UIGesture
//加入手勢偵測
UIPanGestureRecognizer *mapPan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(hideMapItems:)]; //使用者移動時隱藏物件
mapPan.delegate=self;
[mapPan setMinimumNumberOfTouches:1];
[mapPan setMaximumNumberOfTouches:1];
[self.h_map addGestureRecognizer:mapPan];
isMapPanned = NO; //flag
isMapPanned 這邊作為flag, 使用者第一次觸發後就成立,因為這時地圖已經載入完成,不需擔心regionDidChangeAnimated 事件被重複觸發(ios 5.1.1下,ios6 應該也不用擔心?)
另外要注意的是,mapview 不能直接套 UIGesture
因為 MKMapView 有自己的手勢偵測 http://stackoverflow.com/questions/5005597/uipangesturerecognizer-on-mkmapview
所以必須要指定委託並實作方法
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
isMapPanned = YES;
return YES;
}
二、設定相關方法
//檢測使用者畫面移動
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
//使用者開始移動結束,重新顯示物件
if (isMapPanned) {
[self showMapItems:nil];
}
}
此方法不算完美,在網路連線不佳時,有可能發生地圖資料尚未載入完成,使用者就先移動的情況
不過因為相關物件已經載入完成,所以實作上目前沒有看到問題