2012年9月2日 星期日

將相機畫面加到自己的 View 裡面

基本上我們要使用相機來擷取畫面時都是呼叫一個新的 ViewController 出來使用
不過有些時候需要一啟動 App 就載入相機的畫面
這時候有兩個方式:
一個是在 AppDelegate.m 中直接將 UIImagePickerController 加入 rootViewController 中
不過要是需要自定相機的介面的時候就會比較麻煩,因為基本上不會在 AppDelegate.m 中寫太多程式在裡面

另一個是就是跟一般 UI 元件一樣加到現在這個 ViewController 中
用的方法如下:
UIImagePickerController *pickerView = [[UIImagePickerController new] autorelease];
[[self view] addSubview:[pickerView view]];

這樣子就可以在 ViewController.m 中編寫相機的相關功能,而且自定相機介面的時候也不會那麼麻煩。