2013年6月26日 星期三

觸發特定點擊區域

- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
   
    //如果touch到closeButton的區域,就觸發closeButton
    CGPoint pt = [[touches anyObject]locationInView:self.view];
    if (pt.x>closeButton.frame.origin.x &&
        pt.x<closeButton.frame.origin.x+closeButton.frame.size.width &&
        pt.y>closeButton.frame.origin.y &&
        pt.y<closeButton.frame.origin.y+closeButton.frame.size.height)
    {
        [self closeButtonTapped:touches];
    }

}

2013年6月24日 星期一

讀取tmp路徑

NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"temp.pdf"];

2013年6月18日 星期二

objective C 也有 try catch方法

 NSString *test = @"test";
    unichar a;
    int index = 5;

    @try {
        a = [test characterAtIndex:index];
    }
    @catch (NSException *exception) {
        NSLog(@"%@", exception.reason);
    }
    @finally {
        NSLog(@"Char at index %d cannot be found", index);
        NSLog(@"Max index is: %d", [test length]-1);
    }
Log:
[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
Char at index 5 cannot be found
Max index is: 3

C++ assert()的意思

assert 的用法

可用來除錯。

用法很簡單。沒有回傳值,只要 assert() 括號內的值是 false 就直接結束程式,並印出是哪一行、什麼情況下跳出的。

使用前需 include assert.h。

多UIView間touch事件傳值

原本是用一個delegate去選擇touch要停留在那一個UIView回應,
後來發現下面這個方式更好,你可以隨意選擇你要按那一個UIView甚至可以同時觸發二個以上!

把要touch事件trigger寫在UIViewController中,如下面三個function,
然後把要觸發的UIView都加到這個UIViewController中,用下列方式呼叫,
這樣的好處是也可以對父類別的touch事件做呼叫

// Pass touches on to the AR view (EAGLView)
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
  
    // pass events down to parent ViewController
    // super是用來呼叫父類別的方法
    [super touchesBegan:touches withEvent:event];

    // 對自己view做匯入,之後以自己收到的touch去呼叫view的touch事件
    [arViewController.arView touchesBegan:touches withEvent:event];
}


- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event
{
    [arViewController.arView touchesEnded:touches withEvent:event];
}


- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    // Implemented only to prevent the super class methods from executing
}

// 在使用這個方式前,記得在其他view加入下面指令,以確保touch事件都能直接觸到parientViewController
        self.userInteractionEnabled = NO;

2013年6月17日 星期一

XCODE註解與取消註解

縮排 command + [
反向縮排 command + ]
註解 command + /
取消註解 先用反縮排把//移到行首,再按command + / ,即可取消註解

2013年6月13日 星期四

在xcode把沒有git的專案加入git

一,先把專案丟到桌面
二,用xcode在你原本放專案的地方建立一個同名的新專案,記得把create repository打勾
三,關掉xcode
四,刪除新專案資料匣的所有檔案
五,把桌面上你原來專案的檔案拉到新建立同名專案的資料夾中
六,點二下開始專案,就可以看到GIT已經存在了
七,去commit一個新initial commit,因為原來的initial commit是剛剛那個空專案
八,have fun!!