 
 
CMPopTipView 是由 Chris Miles 所撰寫的 Open Source,它提供一種類似 UICalloutView 的效果,由於整個 Tap View 的產是使用 Core Graphic 來繪製,除了可以自行設定顏色外,變化性也更高,關於更多 CMPopTipView 資訊可以參考文章最後的連結。
雖然說 Source Code 中並沒有針對點擊畫面來撰寫事件,但是我們仍然可以透過取得點擊畫面時的座標位置,製作出一個暫時的 UIView 來使用產生 TapView 的方法,其程式碼如下。
//點擊畫面時所觸發的函式
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    //取得點擊的座標位置
    CGPoint point = [[touches anyObject] locationInView:self.view];
    // Toggle popTipView when a standard UIButton is pressed
    if (nil == roundRectButtonPopTipView) {
        roundRectButtonPopTipView = [[[CMPopTipView alloc] initWithMessage:@"Hi Furnace iOS"] autorelease];
        roundRectButtonPopTipView.delegate = self;
        roundRectButtonPopTipView.backgroundColor = [UIColor orangeColor];
        roundRectButtonPopTipView.textColor = [UIColor whiteColor];
        //製作暫時的UIView
        UIView *theView = [[UIButton alloc]initWithFrame:CGRectMake(point.x, point.y, 0.0, 0.0)];
        [roundRectButtonPopTipView presentPointingAtView:theView inView:self.view animated:YES];
        [theView release];
    }
    else {
        // Dismiss
        [roundRectButtonPopTipView dismissAnimated:YES];
        roundRectButtonPopTipView = nil;
    }
}來源位址:GitHub
使用版本:June 21, 2011
測試環境:iOS SDK 4.3
 


 CMPopTipView 提示訊息
 CMPopTipView 提示訊息
 
請問:
回覆刪除照上面打的code有error
roundRectButtonPopTipView
CMPopTipView
這兩個是甚麼
可以詳解嗎?
roundRectButtonPopTipView 你要先宣告唷,它是 CMPopTipView 型態的物件,你可以參考 Open Source 的來源網站,上面程式碼只是我修改 Open Source 部分程式碼的結果。
回覆刪除