iPhone SDK:在相机显示屏上有UIView

时间:2010-07-03 01:20:01

标签: iphone uiview camera

如何在包含相机实时视图的视图上进行UIView?

1 个答案:

答案 0 :(得分:1)

将一个NavigationController放在你的MainWindow.xib中,第一个Controller指向一个自定义的CameraController(类属性)。不要指定任何XIB。

将这个带有IBOutlet的navigationController引用到appDelegate中,然后在laucnch中调用:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

为叠加层创建另一个xib及其控制器,让我们称之为OverlayViewController。

然后进入这个CameraViewController:

·H

   @interface CameraController : UIViewController {
        UIImagePickerController* __picker;
        OverlayViewController* __overlay;
    }

@property (nonatomic, retain) UIImagePickerController* picker;
@property (nonatomic, retain) OverlayViewController* overlay;

的.m

- (void) viewDidLoad {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;

    self.picker.showsCameraControls = NO;
    self.picker.navigationBarHidden = YES;
    self.picker.wantsFullScreenLayout = YES;

    // Insert the overlay
    self.overlay = [[OverlayViewController alloc] initWithNibName:@"Overlay" bundle:nil];
    self.overlay.pickerRef = self.picker;
    self.picker.cameraOverlayView = self.overlay.view;

    [self presentModalViewController:self.picker animated:NO];
}